use of com.android.tools.build.bundletool.model.OptimizationDimension.ABI in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_universal_generatesSingleApkWithNoOptimizations.
@Test
public void buildApksCommand_universal_generatesSingleApkWithNoOptimizations() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", 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)))).addFile("res/drawable-ldpi/image.jpg").addFile("res/drawable-mdpi/image.jpg").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addFileResourceForMultipleConfigs("drawable", "image", ImmutableMap.of(LDPI, "res/drawable-ldpi/image.jpg", MDPI, "res/drawable-mdpi/image.jpg")).build()).setManifest(androidManifest("com.test.app"))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withApkBuildMode(UNIVERSAL).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
// Should not shard by any dimension and generate single APK with default targeting.
assertThat(result.getVariantList()).hasSize(1);
assertThat(splitApkVariants(result)).isEmpty();
assertThat(standaloneApkVariants(result)).hasSize(1);
Variant universalVariant = standaloneApkVariants(result).get(0);
assertThat(universalVariant.getTargeting()).isEqualTo(UNRESTRICTED_VARIANT_TARGETING);
assertThat(apkDescriptions(universalVariant)).hasSize(1);
ApkDescription universalApk = apkDescriptions(universalVariant).get(0);
assertThat(universalApk.getTargeting()).isEqualToDefaultInstance();
// No ABI or density sharding.
File universalApkFile = extractFromApkSetFile(apkSetFile, universalApk.getPath(), outputDir);
try (ZipFile universalApkZipFile = new ZipFile(universalApkFile)) {
assertThat(filesUnderPath(universalApkZipFile, ZipPath.create("lib"))).containsExactly("lib/x86/libsome.so", "lib/x86_64/libsome.so");
// "res/xml/splits0.xml" is created by bundletool with list of generated splits.
assertThat(filesUnderPath(universalApkZipFile, ZipPath.create("res"))).containsExactly("res/drawable-ldpi/image.jpg", "res/drawable-mdpi/image.jpg", "res/xml/splits0.xml");
}
}
use of com.android.tools.build.bundletool.model.OptimizationDimension.ABI in project bundletool by google.
the class BuildApksManagerTest method runSingleConcurrencyTest_disableNativeLibrariesOptimization.
private void runSingleConcurrencyTest_disableNativeLibrariesOptimization(int threadCount) throws Exception {
Path newTempDir = tmp.newFolder().toPath();
outputFilePath = newTempDir.resolve("bundle.apks");
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("assets/file.txt").addFile("dex/classes.dex").setManifest(androidManifest("com.test.app")).setResourceTable(resourceTableWithTestLabel("Test feature"))).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)))).setBundleConfig(BundleConfigBuilder.create().setUncompressNativeLibraries(false).build()).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withExecutorService(MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(threadCount))).withOptimizationDimensions(ABI, LANGUAGE).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
final String manifest = "AndroidManifest.xml";
// Validate split APKs.
ImmutableList<Variant> splitApkVariants = splitApkVariants(result);
assertThat(splitApkVariants).hasSize(1);
ImmutableMap<String, List<ApkDescription>> splitApksByModule = splitApkVariants.get(0).getApkSetList().stream().collect(toImmutableMap(apkSet -> apkSet.getModuleMetadata().getName(), apkSet -> apkSet.getApkDescriptionList()));
assertThat(splitApksByModule.keySet()).containsExactly("base", "abi_feature", "language_feature");
// Correct number of APKs.
// "base" module - master split.
assertThat(splitApksByModule.get("base")).hasSize(1);
// "abi_feature" module - master split + 2 ABI splits.
assertThat(splitApksByModule.get("abi_feature")).hasSize(3);
// "language_feature" module - master split + 3 language splits.
assertThat(splitApksByModule.get("language_feature")).hasSize(4);
// Correct files inside APKs.
assertThat(filesInApks(splitApksByModule.get("base"), apkSetFile)).containsExactly("res/xml/splits0.xml", "resources.arsc", "assets/file.txt", "classes.dex", manifest);
assertThat(filesInApks(splitApksByModule.get("abi_feature"), apkSetFile)).isEqualTo(ImmutableMultiset.builder().add("lib/x86/libsome.so").add("lib/x86_64/libsome.so").addCopies(manifest, 3).build());
assertThat(filesInApks(splitApksByModule.get("language_feature"), apkSetFile)).isEqualTo(ImmutableMultiset.builder().add("res/drawable/image.jpg").add("res/drawable-cz/image.jpg").add("res/drawable-fr/image.jpg").add("res/drawable-pl/image.jpg").addCopies("resources.arsc", 4).addCopies(manifest, 4).build());
// Validate standalone APKs.
ImmutableList<Variant> standaloneVariants = standaloneApkVariants(result);
// Correct number of APKs.
// 2 ABIs
assertThat(standaloneVariants).hasSize(2);
assertThat(apkDescriptions(standaloneVariants)).hasSize(2);
// Correct files inside APKs.
assertThat(filesInApks(apkDescriptions(standaloneVariants), apkSetFile)).isEqualTo(ImmutableMultiset.builder().add("lib/x86/libsome.so").add("lib/x86_64/libsome.so").addCopies("assets/file.txt", 2).addCopies("classes.dex", 2).addCopies("res/drawable/image.jpg", 2).addCopies("res/drawable-cz/image.jpg", 2).addCopies("res/drawable-fr/image.jpg", 2).addCopies("res/drawable-pl/image.jpg", 2).addCopies("res/xml/splits0.xml", 2).addCopies("resources.arsc", 2).addCopies(manifest, 2).build());
}
use of com.android.tools.build.bundletool.model.OptimizationDimension.ABI in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_generateAll_populatesAlternativeVariantTargeting.
@Test
public void buildApksCommand_generateAll_populatesAlternativeVariantTargeting() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", 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(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);
// 2 standalone APK variants, 1 split APK variant
assertThat(result.getVariantList()).hasSize(4);
VariantTargeting lSplitVariantTargeting = variantSdkTargeting(L_SDK_VERSION, ImmutableSet.of(LOWEST_SDK_VERSION, M_SDK_VERSION));
VariantTargeting mSplitVariantTargeting = variantSdkTargeting(M_SDK_VERSION, ImmutableSet.of(LOWEST_SDK_VERSION, L_SDK_VERSION));
VariantTargeting standaloneX86VariantTargeting = mergeVariantTargeting(variantAbiTargeting(X86, ImmutableSet.of(X86_64)), variantSdkTargeting(LOWEST_SDK_VERSION, ImmutableSet.of(L_SDK_VERSION, M_SDK_VERSION)));
VariantTargeting standaloneX64VariantTargeting = mergeVariantTargeting(variantAbiTargeting(X86_64, ImmutableSet.of(X86)), variantSdkTargeting(LOWEST_SDK_VERSION, ImmutableSet.of(L_SDK_VERSION, M_SDK_VERSION)));
ImmutableMap<VariantTargeting, Variant> variantsByTargeting = Maps.uniqueIndex(result.getVariantList(), Variant::getTargeting);
assertThat(ImmutableSet.builder().addAll(apkNamesInVariant(variantsByTargeting.get(lSplitVariantTargeting))).addAll(apkNamesInVariant(variantsByTargeting.get(mSplitVariantTargeting))).build()).containsExactly("base-master.apk", "base-x86.apk", "base-x86_64.apk", "base-master_2.apk", "base-x86_2.apk", "base-x86_64_2.apk");
assertThat(variantsByTargeting.keySet()).containsExactly(lSplitVariantTargeting, mSplitVariantTargeting, standaloneX86VariantTargeting, standaloneX64VariantTargeting);
assertThat(apkNamesInVariant(variantsByTargeting.get(standaloneX86VariantTargeting))).containsExactly("standalone-x86.apk");
assertThat(apkNamesInVariant(variantsByTargeting.get(standaloneX64VariantTargeting))).containsExactly("standalone-x86_64.apk");
}
use of com.android.tools.build.bundletool.model.OptimizationDimension.ABI in project bundletool by google.
the class BuildApksManagerTest method splitFileNames_abi.
@Test
public void splitFileNames_abi() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("dex/classes.dex").addFile("lib/x86/library.so").setManifest(androidManifest("com.test.app")).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86))))).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<VariantTargeting, Variant> splitVariantsByTargeting = Maps.uniqueIndex(splitApkVariants(result), Variant::getTargeting);
VariantTargeting lSplitVariantTargeting = variantSdkTargeting(L_SDK_VERSION, ImmutableSet.of(LOWEST_SDK_VERSION, M_SDK_VERSION));
VariantTargeting mSplitVariantTargeting = variantSdkTargeting(M_SDK_VERSION, ImmutableSet.of(LOWEST_SDK_VERSION, L_SDK_VERSION));
assertThat(splitVariantsByTargeting.keySet()).containsExactly(lSplitVariantTargeting, mSplitVariantTargeting);
assertThat(ImmutableSet.builder().addAll(apkNamesInVariant(splitVariantsByTargeting.get(lSplitVariantTargeting))).addAll(apkNamesInVariant(splitVariantsByTargeting.get(mSplitVariantTargeting))).build()).containsExactly("base-master.apk", "base-x86.apk", "base-master_2.apk", "base-x86_2.apk");
}
Aggregations