use of com.android.bundle.Targeting.Abi in project bundletool by google.
the class ShardedApksFacadeTest method singleModule_withNativeLibsAndDensity_strip64bitNativeLibs.
@Test
@Theory
public void singleModule_withNativeLibsAndDensity_strip64bitNativeLibs(@FromDataPoints("standaloneSplitTypes") SplitType standaloneSplitType) throws Exception {
Optimizations optimizations = Optimizations.newBuilder().setStandaloneConfig(StandaloneConfig.newBuilder().setStrip64BitLibraries(true)).build();
TestComponent.useTestModule(this, standaloneSplitType.equals(SplitType.SYSTEM) ? TestModule.builder().withDeviceSpec(DEVICE_SPEC).withBundleConfig(BundleConfig.newBuilder().setOptimizations(optimizations)).build() : TestModule.builder().withBundleConfig(BundleConfig.newBuilder().setOptimizations(optimizations)).build());
ImmutableList<BundleModule> bundleModule = ImmutableList.of(new BundleModuleBuilder("base").addFile("lib/x86/libsome.so").addFile("lib/x86_64/libsome.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(AbiAlias.X86_64)))).addFile("res/drawable-ldpi/image.jpg").addFile("res/drawable-mdpi/image.jpg").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("image", ImmutableMap.of(LDPI_VALUE, "res/drawable-ldpi/image.jpg", MDPI_VALUE, "res/drawable-mdpi/image.jpg")).build()).setManifest(androidManifest("com.test.app")).build());
ImmutableList<ModuleSplit> moduleSplits;
if (standaloneSplitType.equals(SplitType.SYSTEM)) {
moduleSplits = shardedApksFacade.generateSystemSplits(bundleModule, ImmutableSet.of(BASE_MODULE_NAME), DEFAULT_APK_OPTIMIZATIONS);
// x86, mdpi split
assertThat(moduleSplits).hasSize(1);
} else {
moduleSplits = shardedApksFacade.generateSplits(bundleModule, DEFAULT_APK_OPTIMIZATIONS);
// 7 (density), 1 (abi) split
assertThat(moduleSplits).hasSize(7);
}
// Verify that the only ABI is x86.
ImmutableSet<Abi> abiTargetings = moduleSplits.stream().map(ModuleSplit::getApkTargeting).map(ApkTargeting::getAbiTargeting).map(AbiTargeting::getValueList).flatMap(List::stream).collect(toImmutableSet());
assertThat(abiTargetings).containsExactly(toAbi(X86));
// And ABI has no alternatives.
ImmutableSet<Abi> abiAlternatives = moduleSplits.stream().map(ModuleSplit::getApkTargeting).map(ApkTargeting::getAbiTargeting).map(AbiTargeting::getAlternativesList).flatMap(List::stream).collect(toImmutableSet());
assertThat(abiAlternatives).isEmpty();
assertThat(moduleSplits.stream().map(ModuleSplit::getSplitType).collect(toImmutableSet())).containsExactly(standaloneSplitType);
}
use of com.android.bundle.Targeting.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());
}
}
use of com.android.bundle.Targeting.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.bundle.Targeting.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.bundle.Targeting.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");
}
Aggregations