com.android.bundle.Files.NativeLibraries Java Examples
The following examples show how to use
com.android.bundle.Files.NativeLibraries.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BundleModuleTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void specialFiles_areNotStoredAsEntries() throws Exception { BundleModule bundleModule = BundleModule.builder() .setName(BundleModuleName.create("testModule")) .setBundleConfig(DEFAULT_BUNDLE_CONFIG) .addEntry( createModuleEntryForFile( "manifest/AndroidManifest.xml", androidManifest("com.test.app").toByteArray())) .addEntry( createModuleEntryForFile("assets.pb", Assets.getDefaultInstance().toByteArray())) .addEntry( createModuleEntryForFile( "native.pb", NativeLibraries.getDefaultInstance().toByteArray())) .addEntry( createModuleEntryForFile( "resources.pb", ResourceTable.getDefaultInstance().toByteArray())) .build(); assertThat(bundleModule.getEntries()).isEmpty(); }
Example #2
Source File: NativeTargetingValidatorTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void validateModule_valid_succeeds() throws Exception { NativeLibraries config = nativeLibraries( targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)), targetedNativeDirectory("lib/mips", nativeDirectoryTargeting(MIPS))); BundleModule module = new BundleModuleBuilder("testModule") .setNativeConfig(config) .addFile("lib/x86/libX.so") .addFile("lib/x86_64/libX.so") .addFile("lib/mips/libX.so") .setManifest(androidManifest("com.test.app")) .build(); new NativeTargetingValidator().validateModule(module); }
Example #3
Source File: AssetModuleFilesValidatorTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void moduleWithNativeConfig_throws() throws Exception { NativeLibraries config = nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(DXT1))); BundleModule module = new BundleModuleBuilder(MODULE_NAME) .setManifest(androidManifestForAssetModule(PKG_NAME)) .setNativeConfig(config) .build(); InvalidBundleException exception = assertThrows( InvalidBundleException.class, () -> new AssetModuleFilesValidator().validateModule(module)); assertThat(exception) .hasMessageThat() .matches("Native libraries config not allowed in asset packs, but found in 'assetmodule'."); }
Example #4
Source File: StandaloneApkSerializer.java From bundletool with Apache License 2.0 | 6 votes |
private static ImmutableSet<Abi> getTargetedAbis(ModuleSplit split) { // We cannot rely on split.getNativeConfig() which might be not exist // Instead, we use the entry paths to check ABIs Collection<String> nativeLibDirs = split.getEntries().stream() .filter( entry -> { String path = entry.getPath().toString(); return path.startsWith("lib/") && path.endsWith(".so"); }) .map(entry -> entry.getPath().getParent().toString()) .collect(toImmutableSet()); if (nativeLibDirs.isEmpty()) { return ImmutableSet.of(); } NativeLibraries nativeLibraries = new TargetingGenerator().generateTargetingForNativeLibraries(nativeLibDirs); return nativeLibraries.getDirectoryList().stream() .map(TargetedNativeDirectory::getTargeting) .map(NativeDirectoryTargeting::getAbi) .collect(toImmutableSet()); }
Example #5
Source File: NativeTargetingValidatorTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void validateModule_abiTargetingDimensionNotSet_throws() throws Exception { NativeLibraries config = nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(DXT1))); BundleModule module = new BundleModuleBuilder("testModule") .addFile("lib/x86/libX.so") .setNativeConfig(config) .setManifest(androidManifest("com.test.app")) .build(); InvalidBundleException e = assertThrows( InvalidBundleException.class, () -> new NativeTargetingValidator().validateModule(module)); assertThat(e) .hasMessageThat() .contains("Targeted native directory 'lib/x86' does not have the ABI dimension set"); }
Example #6
Source File: NativeTargetingValidatorTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void validateModule_pathOutsideLib_throws() throws Exception { NativeLibraries config = nativeLibraries( targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("assets/lib/x86_64", nativeDirectoryTargeting(X86_64))); BundleModule module = new BundleModuleBuilder("testModule") .setNativeConfig(config) .addFile("lib/x86/libX.so") .setManifest(androidManifest("com.test.app")) .build(); InvalidBundleException e = assertThrows( InvalidBundleException.class, () -> new NativeTargetingValidator().validateModule(module)); assertThat(e).hasMessageThat().contains("directory must be in format 'lib/<directory>'"); }
Example #7
Source File: NativeTargetingValidatorTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void validateModule_pointDirectlyToLib_throws() throws Exception { NativeLibraries config = nativeLibraries(targetedNativeDirectory("lib/", nativeDirectoryTargeting(X86_64))); BundleModule module = new BundleModuleBuilder("testModule") .setNativeConfig(config) .setManifest(androidManifest("com.test.app")) .build(); InvalidBundleException e = assertThrows( InvalidBundleException.class, () -> new NativeTargetingValidator().validateModule(module)); assertThat(e).hasMessageThat().contains("directory must be in format 'lib/<directory>'"); }
Example #8
Source File: NativeTargetingValidatorTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void validateModule_emptyTargetedDirectory_throws() throws Exception { NativeLibraries config = nativeLibraries( targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)), targetedNativeDirectory("lib/mips", nativeDirectoryTargeting(MIPS))); BundleModule module = new BundleModuleBuilder("testModule") .setNativeConfig(config) .addFile("lib/x86/libX.so") .addFile("lib/x86_64/libX.so") .setManifest(androidManifest("com.test.app")) .build(); InvalidBundleException e = assertThrows( InvalidBundleException.class, () -> new NativeTargetingValidator().validateModule(module)); assertThat(e).hasMessageThat().contains("Targeted directory 'lib/mips' is empty."); }
Example #9
Source File: NativeTargetingValidatorTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void validateModule_directoriesUnderLibNotTargeted_throws() throws Exception { NativeLibraries config = nativeLibraries( targetedNativeDirectory("lib/mips", nativeDirectoryTargeting(MIPS))); BundleModule module = new BundleModuleBuilder("testModule") .addFile("lib/x86/libX.so") .addFile("lib/x86_64/libX.so") .addFile("lib/mips/libX.so") .setNativeConfig(config) .setManifest(androidManifest("com.test.app")) .build(); InvalidBundleException e = assertThrows( InvalidBundleException.class, () -> new NativeTargetingValidator().validateModule(module)); assertThat(e).hasMessageThat() .contains("Following native directories are not targeted: [lib/x86, lib/x86_64]"); }
Example #10
Source File: AppBundle64BitNativeLibrariesPreprocessor.java From bundletool with Apache License 2.0 | 6 votes |
private static BundleModule processModule(BundleModule module) { Optional<NativeLibraries> nativeConfig = module.getNativeConfig(); if (!nativeConfig.isPresent()) { return module; } ImmutableSet<TargetedNativeDirectory> dirsToRemove = get64BitTargetedNativeDirectories(nativeConfig.get()); if (dirsToRemove.isEmpty()) { return module; } if (dirsToRemove.size() == nativeConfig.get().getDirectoryCount()) { throw InvalidBundleException.builder() .withUserMessage( "Usage of 64-bit native libraries is disabled by the presence of a " + "renderscript file, but App Bundle contains only 64-bit native libraries.") .build(); } return module.toBuilder() .setRawEntries(processEntries(module.getEntries(), dirsToRemove)) .setNativeConfig(processTargeting(nativeConfig.get(), dirsToRemove)) .build(); }
Example #11
Source File: EntryClashValidatorTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void differentNativeConfig_ok() throws Exception { String filePath = "native.pb"; byte[] fileContentA = NativeLibraries.getDefaultInstance().toByteArray(); byte[] fileContentB = NativeLibraries.newBuilder() .addDirectory(TargetedNativeDirectory.getDefaultInstance()) .build() .toByteArray(); assertThat(fileContentA).isNotEqualTo(fileContentB); BundleModule moduleA = new BundleModuleBuilder("a") .addFile(filePath, fileContentA) .setManifest(androidManifest("com.test.app")) .build(); BundleModule moduleB = new BundleModuleBuilder("b") .addFile(filePath, fileContentB) .setManifest(androidManifest("com.test.app")) .build(); new EntryClashValidator().validateAllModules(ImmutableList.of(moduleA, moduleB)); }
Example #12
Source File: TargetingGenerator.java From bundletool with Apache License 2.0 | 6 votes |
/** * Processes given native library directories, generating targeting based on their names. * * @param libDirectories Names of directories under lib/, including the "lib/" prefix. * @return Targeting for the given native libraries directories. */ public NativeLibraries generateTargetingForNativeLibraries(Collection<String> libDirectories) { NativeLibraries.Builder nativeLibraries = NativeLibraries.newBuilder(); for (String directory : libDirectories) { checkRootDirectoryName(LIB_DIR, directory); // Split the directory under lib/ into tokens. String subDirName = directory.substring(LIB_DIR.length()); Abi abi = checkAbiName(subDirName, directory); NativeDirectoryTargeting.Builder nativeBuilder = NativeDirectoryTargeting.newBuilder().setAbi(abi); if (subDirName.equals("arm64-v8a-hwasan")) { nativeBuilder.setSanitizer(Sanitizer.newBuilder().setAlias(SanitizerAlias.HWADDRESS)); } nativeLibraries.addDirectory( TargetedNativeDirectory.newBuilder() .setPath(directory) .setTargeting(nativeBuilder) .build()); } return nativeLibraries.build(); }
Example #13
Source File: ModuleAbiSanitizer.java From bundletool with Apache License 2.0 | 6 votes |
private static NativeLibraries filterNativeTargeting( NativeLibraries nativeLibraries, ImmutableMultimap<ZipPath, ModuleEntry> preservedEntriesByAbiDir) { ImmutableSet<String> preservedAbiDirs = preservedEntriesByAbiDir.keySet().stream().map(ZipPath::toString).collect(toImmutableSet()); return nativeLibraries .toBuilder() .clearDirectory() .addAllDirectory( nativeLibraries.getDirectoryList().stream() .filter(targetedDirectory -> preservedAbiDirs.contains(targetedDirectory.getPath())) .collect(toImmutableList())) .build(); }
Example #14
Source File: ModuleAbiSanitizer.java From bundletool with Apache License 2.0 | 6 votes |
private static BundleModule sanitizedModule( BundleModule module, ImmutableMultimap<ZipPath, ModuleEntry> libFilesByAbiDirToKeep) { // Construct new module by making minimal modifications to the existing module. BundleModule.Builder newModule = module.toBuilder(); if (module.getNativeConfig().isPresent()) { NativeLibraries newNativeConfig = filterNativeTargeting(module.getNativeConfig().get(), libFilesByAbiDirToKeep); newModule.setNativeConfig(newNativeConfig); } newModule.setEntryMap( module.getEntries().stream() .filter( entry -> !entry.getPath().startsWith(LIB_DIRECTORY) || libFilesByAbiDirToKeep.containsValue(entry)) .collect(toImmutableMap(ModuleEntry::getPath, Function.identity()))); return newModule.build(); }
Example #15
Source File: ModuleSplitsToShardMergerTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test public void nativeConfigs_defaultAndNonDefault_ok() throws Exception { ModuleSplit splitNonDefault = createModuleSplitBuilder() .setNativeConfig( nativeLibraries( targetedNativeDirectory("lib/mips", nativeDirectoryTargeting(MIPS)))) .build(); ModuleSplit splitDefault = createModuleSplitBuilder().setNativeConfig(NativeLibraries.getDefaultInstance()).build(); // We don't care about the merged result, just that the merging succeeds. new ModuleSplitsToShardMerger(d8DexMerger, getCurrentVersion(), tmpDir) .mergeSingleShard( ImmutableList.of(splitNonDefault, splitDefault), NO_MAIN_DEX_LIST, createCache()); new ModuleSplitsToShardMerger(d8DexMerger, getCurrentVersion(), tmpDir) .mergeSingleShard( ImmutableList.of(splitDefault, splitNonDefault), NO_MAIN_DEX_LIST, createCache()); }
Example #16
Source File: NativeLibsCompressionVariantGeneratorTest.java From bundletool with Apache License 2.0 | 6 votes |
/** Creates a minimal module with one native library targeted at the given cpu architecture. */ private static BundleModule createSingleLibraryModule( String moduleName, String architecture, String relativeFilePath, ManifestMutator... manifestMutators) throws Exception { NativeLibraries nativeConfig = nativeLibraries( targetedNativeDirectory("lib/" + architecture, nativeDirectoryTargeting(architecture))); return new BundleModuleBuilder(moduleName) .addFile(relativeFilePath) .setNativeConfig(nativeConfig) .setManifest(androidManifest("com.test.app", manifestMutators)) .build(); }
Example #17
Source File: BuildBundleCommand.java From bundletool with Apache License 2.0 | 6 votes |
private static Optional<NativeLibraries> generateNativeLibrariesTargeting(BundleModule module) { // Validation ensures that files under "lib/" conform to pattern "lib/<abi-dir>/file.so". // We extract the distinct "lib/<abi-dir>" directories. ImmutableList<String> libAbiDirs = module .findEntriesUnderPath(BundleModule.LIB_DIRECTORY) .map(ModuleEntry::getPath) .filter(path -> path.getNameCount() > 2) .map(path -> path.subpath(0, 2)) .map(ZipPath::toString) .distinct() .collect(toImmutableList()); if (libAbiDirs.isEmpty()) { return Optional.empty(); } return Optional.of(new TargetingGenerator().generateTargetingForNativeLibraries(libAbiDirs)); }
Example #18
Source File: NativeLibrariesCompressionSplitterTest.java From bundletool with Apache License 2.0 | 6 votes |
/** Creates a minimal module with one native library targeted at the given cpu architecture. */ private static BundleModule createSingleLibraryModule( String moduleName, String architecture, String relativeFilePath, ManifestMutator... manifestMutators) throws Exception { NativeLibraries nativeConfig = nativeLibraries( targetedNativeDirectory("lib/" + architecture, nativeDirectoryTargeting(architecture))); return new BundleModuleBuilder(moduleName) .addFile(relativeFilePath) .setNativeConfig(nativeConfig) .setManifest(androidManifest("com.test.app", manifestMutators)) .build(); }
Example #19
Source File: BuildBundleCommandTest.java From bundletool with Apache License 2.0 | 5 votes |
@Test public void nativeLibrariesPresent_abiTargetingIsPresent() throws Exception { Path moduleWithAbi = new ZipBuilder() .addFileWithContent(ZipPath.create("lib/x86/libfast.so"), "native data".getBytes(UTF_8)) .addFileWithContent( ZipPath.create("lib/x86/libfaster.so"), "native data".getBytes(UTF_8)) .addFileWithProtoContent( ZipPath.create("manifest/AndroidManifest.xml"), androidManifest(PKG_NAME)) .writeTo(tmpDir.resolve("base.zip")); BuildBundleCommand.builder() .setOutputPath(bundlePath) .setModulesPaths(ImmutableList.of(moduleWithAbi)) .build() .execute(); NativeLibraries actualTargeting; try (ZipFile bundle = new ZipFile(bundlePath.toFile())) { assertThat(bundle).hasFile("base/native.pb"); actualTargeting = NativeLibraries.parseFrom(bundle.getInputStream(new ZipEntry("base/native.pb"))); } NativeLibraries expectedTargeting = NativeLibraries.newBuilder() .addDirectory( TargetedNativeDirectory.newBuilder() .setPath("lib/x86") .setTargeting( NativeDirectoryTargeting.newBuilder() .setAbi(Abi.newBuilder().setAlias(X86)))) .build(); Truth.assertThat(actualTargeting).isEqualTo(expectedTargeting); }
Example #20
Source File: ModuleSplitterTest.java From bundletool with Apache License 2.0 | 5 votes |
@Test public void testSplitsDontHaveBundleConfigFiles() throws Exception { BundleModule bundleModule = new BundleModuleBuilder("testModule") .addFile("assets/dict.dat") .setManifest(androidManifest("com.test.app")) .setNativeConfig(NativeLibraries.getDefaultInstance()) .setAssetsConfig(Assets.getDefaultInstance()) .build(); ImmutableList<ModuleSplit> splits = createAbiAndDensitySplitter(bundleModule).splitModule(); assertThat(splits.stream().map(ModuleSplit::getSplitType).distinct().collect(toImmutableSet())) .containsExactly(SplitType.SPLIT); assertThat( splits .stream() .map(ModuleSplit::getVariantTargeting) .distinct() .collect(toImmutableSet())) .containsExactly(lPlusVariantTargeting()); assertThat(splits).isNotEmpty(); for (ModuleSplit split : splits) { ImmutableSet<ZipPath> pathEntries = split.getEntries().stream().map(ModuleEntry::getPath).collect(toImmutableSet()); assertThat(pathEntries).doesNotContain(ZipPath.create("native.pb")); assertThat(pathEntries).doesNotContain(ZipPath.create("assets.pb")); } }
Example #21
Source File: ModuleAbiSanitizerTest.java From bundletool with Apache License 2.0 | 5 votes |
@Test public void consistentNativeLibraries_moduleUnchanged() throws Exception { NativeLibraries nativeConfig = nativeLibraries( targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)), targetedNativeDirectory("lib/mips", nativeDirectoryTargeting(MIPS))); BundleModule testModule = new BundleModuleBuilder("testModule") .addFile("lib/x86/lib1.so") .addFile("lib/x86/lib2.so") .addFile("lib/x86/lib3.so") .addFile("lib/x86_64/lib1.so") .addFile("lib/x86_64/lib2.so") .addFile("lib/x86_64/lib3.so") .addFile("lib/mips/lib1.so") .addFile("lib/mips/lib2.so") .addFile("lib/mips/lib3.so") .setNativeConfig(nativeConfig) .setManifest(androidManifest("com.test.app")) .build(); BundleModule sanitizedModule = new ModuleAbiSanitizer().sanitize(testModule); assertThat(sanitizedModule.getNativeConfig().get()) .isEqualTo(testModule.getNativeConfig().get()); assertThat(sanitizedModule.getEntries()).containsExactlyElementsIn(testModule.getEntries()); // Sanity check that nothing else changed as well. assertThat(sanitizedModule).isEqualTo(testModule); }
Example #22
Source File: ModuleAbiSanitizerTest.java From bundletool with Apache License 2.0 | 5 votes |
@Test public void inconsistentNativeLibraries_libFilesFilteredAwayAndNativeTargetingAdjusted() throws Exception { NativeLibraries nativeConfig = nativeLibraries( targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)), targetedNativeDirectory("lib/mips", nativeDirectoryTargeting(MIPS))); BundleModule testModule = new BundleModuleBuilder("testModule") .addFile("lib/x86/lib1.so") .addFile("lib/x86/lib2.so") .addFile("lib/x86/lib3.so") .addFile("lib/x86_64/lib1.so") .addFile("lib/x86_64/lib2.so") .addFile("lib/mips/lib1.so") .setNativeConfig(nativeConfig) .setManifest(androidManifest("com.test.app")) .build(); BundleModule sanitizedModule = new ModuleAbiSanitizer().sanitize(testModule); assertThat( sanitizedModule .getEntries() .stream() .map(ModuleEntry::getPath) .filter(entryPath -> entryPath.startsWith(ZipPath.create("lib"))) .map(ZipPath::toString)) .containsExactly("lib/x86/lib1.so", "lib/x86/lib2.so", "lib/x86/lib3.so"); assertThat(sanitizedModule.getNativeConfig().get()) .isEqualTo( nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)))); }
Example #23
Source File: TargetingGeneratorTest.java From bundletool with Apache License 2.0 | 5 votes |
@Test public void generateTargetingForNativeLibraries_createsSingleDirectoryGroup() throws Exception { Collection<String> manyDirectories = Arrays.stream(AbiName.values()) .map(AbiName::getPlatformName) .map(abi -> "lib/" + abi) .collect(toImmutableList()); checkState(manyDirectories.size() > 1); // Otherwise this test is useless. NativeLibraries nativeTargeting = generator.generateTargetingForNativeLibraries(manyDirectories); List<TargetedNativeDirectory> directories = nativeTargeting.getDirectoryList(); assertThat(directories).hasSize(manyDirectories.size()); }
Example #24
Source File: TargetingGeneratorTest.java From bundletool with Apache License 2.0 | 5 votes |
@Test public void generateTargetingForNativeLibraries_sanitizer() throws Exception { NativeLibraries nativeTargeting = generator.generateTargetingForNativeLibraries(ImmutableList.of("lib/arm64-v8a-hwasan")); List<TargetedNativeDirectory> directories = nativeTargeting.getDirectoryList(); assertThat(directories).hasSize(1); assertThat(directories.get(0)) .isEqualTo( TargetedNativeDirectory.newBuilder() .setPath("lib/arm64-v8a-hwasan") .setTargeting( nativeDirectoryTargeting(AbiAlias.ARM64_V8A, SanitizerAlias.HWADDRESS)) .build()); }
Example #25
Source File: BundleModuleTest.java From bundletool with Apache License 2.0 | 5 votes |
@Test public void correctNativeProtoFile_parsedAndReturned() throws Exception { NativeLibraries nativeConfig = NativeLibraries.newBuilder() .addDirectory(TargetedNativeDirectory.newBuilder().setPath("native/x86")) .build(); BundleModule bundleModule = createMinimalModuleBuilder() .addEntry(createModuleEntryForFile("native.pb", nativeConfig.toByteArray())) .build(); assertThat(bundleModule.getNativeConfig()).hasValue(nativeConfig); }
Example #26
Source File: VariantGeneratorTest.java From bundletool with Apache License 2.0 | 5 votes |
private static BundleModule createSingleLibraryDexModule(XmlNode androidManifest) throws Exception { NativeLibraries nativeConfig = nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting("x86"))); return new BundleModuleBuilder("testModule") .setManifest(androidManifest) .setNativeConfig(nativeConfig) .addFile("lib/x86/liba.so") .addFile("dex/classes.dex") .build(); }
Example #27
Source File: AbiNativeLibrariesSplitterTest.java From bundletool with Apache License 2.0 | 5 votes |
/** Creates a minimal module with one native library targeted at the given cpu architecture. */ private static BundleModule createSingleLibraryModule( String moduleName, String architecture, String relativeFilePath) throws Exception { NativeLibraries nativeConfig = nativeLibraries( targetedNativeDirectory("lib/" + architecture, nativeDirectoryTargeting(architecture))); return new BundleModuleBuilder(moduleName) .addFile(relativeFilePath) .setNativeConfig(nativeConfig) .setManifest(androidManifest("com.test.app")) .build(); }
Example #28
Source File: ModuleSplitterTest.java From bundletool with Apache License 2.0 | 5 votes |
@Test public void nativeSplits_lPlusTargeting_withAbiAndUncompressNativeLibsSplitter() throws Exception { NativeLibraries nativeConfig = nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting("x86"))); BundleModule testModule = new BundleModuleBuilder("testModule") .setManifest(androidManifest("com.test.app")) .setNativeConfig(nativeConfig) .addFile("lib/x86/liba.so") .build(); ModuleSplitter moduleSplitter = ModuleSplitter.createNoStamp( testModule, BUNDLETOOL_VERSION, ApkGenerationConfiguration.builder() .setOptimizationDimensions(ImmutableSet.of(ABI)) .setEnableNativeLibraryCompressionSplitter(true) .build(), lPlusVariantTargeting(), ImmutableSet.of("testModule")); List<ModuleSplit> splits = moduleSplitter.splitModule(); // Base + X86 Split assertThat(splits).hasSize(2); assertThat(splits.stream().map(ModuleSplit::getSplitType).distinct().collect(toImmutableSet())) .containsExactly(SplitType.SPLIT); assertThat(splits.stream().map(split -> split.getVariantTargeting()).collect(toImmutableSet())) .containsExactly(variantMinSdkTargeting(ANDROID_L_API_VERSION)); ModuleSplit x86Split = splits.stream() .filter(split -> split.getApkTargeting().hasAbiTargeting()) .findFirst() .get(); assertThat(x86Split.findEntry("lib/x86/liba.so").get().getForceUncompressed()).isFalse(); }
Example #29
Source File: BundleModuleMerger.java From bundletool with Apache License 2.0 | 5 votes |
private static Optional<NativeLibraries> mergeNativeLibraryTable( ImmutableSet<BundleModule> bundleModulesToFuse) { if (bundleModulesToFuse.stream().noneMatch(module -> module.getNativeConfig().isPresent())) { return Optional.empty(); } NativeLibraries.Builder nativeLibrariesMerged = NativeLibraries.newBuilder(); for (BundleModule bundleModule : bundleModulesToFuse) { bundleModule.getNativeConfig().ifPresent(nativeLibrariesMerged::mergeFrom); } return Optional.of(nativeLibrariesMerged.build()); }
Example #30
Source File: NativeLibrariesHelper.java From bundletool with Apache License 2.0 | 5 votes |
private static boolean hasMainLibrary( Optional<NativeLibraries> nativeConfig, ImmutableCollection<ModuleEntry> entries) { List<ZipPath> nativeLibPaths = stream(nativeConfig) .flatMap(config -> config.getDirectoryList().stream()) .map(directory -> ZipPath.create(directory.getPath())) .collect(toImmutableList()); return entries.stream() .anyMatch( entry -> entry.getPath().endsWith(MAIN_NATIVE_LIBRARY) && nativeLibPaths.stream().anyMatch(entry.getPath()::startsWith)); }