use of com.android.tools.build.bundletool.model.OptimizationDimension.ABI in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_standalone_mixedTargeting.
@Test
public void buildApksCommand_standalone_mixedTargeting() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.test.app")).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("feature_abi_lib", builder -> builder.addFile("lib/x86/libfeature.so").addFile("lib/x86_64/libfeature.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)))).setManifest(androidManifestForFeature("com.test.app", withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).addModule("feature_lang_assets", builder -> builder.addFile("assets/strings#lang_en/trans.txt").addFile("assets/strings#lang_fr/trans.txt").setAssetsConfig(assets(targetedAssetsDirectory("assets/strings#lang_en", assetsDirectoryTargeting(languageTargeting("en"))), targetedAssetsDirectory("assets/strings#lang_fr", assetsDirectoryTargeting(languageTargeting("fr"))))).setManifest(androidManifestForFeature("com.test.app", withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).addModule("feature_tcf_assets", builder -> builder.addFile("assets/textures#tcf_atc/texture.dat").addFile("assets/textures#tcf_etc1/texture.dat").setAssetsConfig(assets(targetedAssetsDirectory("assets/textures#tcf_atc", assetsDirectoryTargeting(textureCompressionTargeting(ATC))), targetedAssetsDirectory("assets/textures#tcf_etc1", assetsDirectoryTargeting(textureCompressionTargeting(ETC1_RGB8))))).setManifest(androidManifestForFeature("com.test.app", withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withOptimizationDimensions(ABI).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
ImmutableMap<Abi, ApkDescription> standaloneApksByAbi = Maps.uniqueIndex(apkDescriptions(standaloneApkVariants(result)), apkDesc -> getOnlyElement(apkDesc.getTargeting().getAbiTargeting().getValueList()));
assertThat(standaloneApksByAbi.keySet()).containsExactly(toAbi(X86), toAbi(X86_64));
File x86ApkFile = extractFromApkSetFile(apkSetFile, standaloneApksByAbi.get(toAbi(X86)).getPath(), outputDir);
try (ZipFile x86Zip = new ZipFile(x86ApkFile)) {
// ABI-specific files.
assertThat(x86Zip).hasFile("lib/x86/libfeature.so");
assertThat(x86Zip).doesNotHaveFile("lib/x86_64/libfeature.so");
// Included in each standalone APK.
assertThat(x86Zip).hasFile("assets/strings#lang_en/trans.txt");
assertThat(x86Zip).hasFile("assets/strings#lang_fr/trans.txt");
assertThat(x86Zip).hasFile("assets/textures#tcf_atc/texture.dat");
assertThat(x86Zip).hasFile("assets/textures#tcf_etc1/texture.dat");
}
File x64ApkFile = extractFromApkSetFile(apkSetFile, standaloneApksByAbi.get(toAbi(X86_64)).getPath(), outputDir);
try (ZipFile x64Zip = new ZipFile(x64ApkFile)) {
// ABI-specific files.
assertThat(x64Zip).hasFile("lib/x86_64/libfeature.so");
assertThat(x64Zip).doesNotHaveFile("lib/x86/libfeature.so");
// Included in each standalone APK.
assertThat(x64Zip).hasFile("assets/strings#lang_en/trans.txt");
assertThat(x64Zip).hasFile("assets/strings#lang_fr/trans.txt");
assertThat(x64Zip).hasFile("assets/textures#tcf_atc/texture.dat");
assertThat(x64Zip).hasFile("assets/textures#tcf_etc1/texture.dat");
}
}
use of com.android.tools.build.bundletool.model.OptimizationDimension.ABI in project bundletool by google.
the class ModuleSplitterTest method nativeSplits_lPlusTargeting_withAbiAndUncompressNativeLibsSplitter.
@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, APP_BUNDLE, ApkGenerationConfiguration.builder().setOptimizationDimensions(ImmutableSet.of(ABI)).setEnableUncompressedNativeLibraries(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 master = splits.stream().filter(ModuleSplit::isMasterSplit).collect(onlyElement());
ModuleSplit abi = splits.stream().filter(not(ModuleSplit::isMasterSplit)).collect(onlyElement());
assertThat(master.getAndroidManifest().getExtractNativeLibsValue()).hasValue(true);
assertThat(abi.findEntry("lib/x86/liba.so").get().getForceUncompressed()).isFalse();
}
use of com.android.tools.build.bundletool.model.OptimizationDimension.ABI in project bundletool by google.
the class ModuleSplitterTest method nativeSplits_mPlusTargeting_withAbiAndUncompressNativeLibsSplitter.
@Test
public void nativeSplits_mPlusTargeting_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, APP_BUNDLE, ApkGenerationConfiguration.builder().setOptimizationDimensions(ImmutableSet.of(ABI)).setEnableUncompressedNativeLibraries(true).build(), variantMinSdkTargeting(ANDROID_M_API_VERSION), 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_M_API_VERSION));
ModuleSplit master = splits.stream().filter(ModuleSplit::isMasterSplit).collect(onlyElement());
ModuleSplit abi = splits.stream().filter(not(ModuleSplit::isMasterSplit)).collect(onlyElement());
assertThat(master.getAndroidManifest().getExtractNativeLibsValue()).hasValue(false);
assertThat(abi.findEntry("lib/x86/liba.so").get().getForceUncompressed()).isTrue();
}
use of com.android.tools.build.bundletool.model.OptimizationDimension.ABI in project bundletool by google.
the class BuildApksManagerTest method extractApkSet_outputApksWithoutArchive.
@Test
public void extractApkSet_outputApksWithoutArchive() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("assets/file.txt").addFile("dex/classes.dex").setManifest(androidManifest("com.test.app")).setResourceTable(resourceTableWithTestLabel("test_label"))).addModule("abi_feature", builder -> builder.addFile("lib/x86/libsome.so").addFile("lib/x86_64/libsome.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)))).setManifest(androidManifestForFeature("com.test.app", withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).addModule("language_feature", builder -> builder.addFile("res/drawable/image.jpg").addFile("res/drawable-cz/image.jpg").addFile("res/drawable-fr/image.jpg").addFile("res/drawable-pl/image.jpg").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app", USER_PACKAGE_OFFSET - 1).addFileResourceForMultipleConfigs("drawable", "image", ImmutableMap.of(Configuration.getDefaultInstance(), "res/drawable/image.jpg", locale("cz"), "res/drawable-cz/image.jpg", locale("fr"), "res/drawable-fr/image.jpg", locale("pl"), "res/drawable-pl/image.jpg")).build()).setManifest(androidManifestForFeature("com.test.app", withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputDir).withOptimizationDimensions(ABI, LANGUAGE).withCustomBuildApksCommandSetter(command -> command.setOutputFormat(DIRECTORY)).build());
buildApksManager.execute();
assertThat(command.getOutputFile()).isEqualTo(outputDir);
BuildApksResult result = parseTocFromFile(outputDir.resolve("toc.pb").toFile());
// Validate all APKs were created.
verifyApksExist(apkDescriptions(result.getVariantList()), outputDir);
}
use of com.android.tools.build.bundletool.model.OptimizationDimension.ABI in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_standalone_oneModuleManyVariants.
@Test
public void buildApksCommand_standalone_oneModuleManyVariants() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("dex/classes.dex").addFile("lib/x86/libsome.so").addFile("lib/x86_64/libsome.so").addFile("lib/mips/libsome.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)), targetedNativeDirectory("lib/mips", nativeDirectoryTargeting(MIPS)))).setManifest(androidManifest("com.test.app"))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withOptimizationDimensions(ABI).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
ImmutableMap<Abi, Variant> standaloneVariantsByAbi = Maps.uniqueIndex(standaloneApkVariants(result), variant -> {
ApkDescription apkDescription = getOnlyElement(apkDescriptions(variant));
return getOnlyElement(apkDescription.getTargeting().getAbiTargeting().getValueList());
});
assertThat(standaloneVariantsByAbi.keySet()).containsExactly(toAbi(X86), toAbi(X86_64), toAbi(MIPS));
assertThat(standaloneVariantsByAbi.get(toAbi(X86)).getTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeVariantTargeting(variantAbiTargeting(X86, ImmutableSet.of(X86_64, MIPS)), variantSdkTargeting(LOWEST_SDK_VERSION, ImmutableSet.of(L_SDK_VERSION, M_SDK_VERSION))));
assertThat(standaloneVariantsByAbi.get(toAbi(X86_64)).getTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeVariantTargeting(variantAbiTargeting(X86_64, ImmutableSet.of(X86, MIPS)), variantSdkTargeting(LOWEST_SDK_VERSION, ImmutableSet.of(L_SDK_VERSION, M_SDK_VERSION))));
assertThat(standaloneVariantsByAbi.get(toAbi(MIPS)).getTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeVariantTargeting(variantAbiTargeting(MIPS, ImmutableSet.of(X86, X86_64)), variantSdkTargeting(LOWEST_SDK_VERSION, ImmutableSet.of(L_SDK_VERSION, M_SDK_VERSION))));
for (Variant variant : standaloneVariantsByAbi.values()) {
assertThat(variant.getApkSetList()).hasSize(1);
ApkSet apkSet = variant.getApkSet(0);
assertThat(apkSet.getApkDescriptionList()).hasSize(1);
assertThat(apkSetFile).hasFile(apkSet.getApkDescription(0).getPath());
}
}
Aggregations