use of com.android.bundle.Targeting.Abi.AbiAlias.X86 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.AbiAlias.X86 in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_apkNotificationMessageKeyApexBundle_previewTargetSdk.
@Test
public void buildApksCommand_apkNotificationMessageKeyApexBundle_previewTargetSdk() throws Exception {
ApexImages apexConfig = apexImages(targetedApexImage("apex/x86_64.img", apexImageTargeting("x86_64")), targetedApexImage("apex/x86.img", apexImageTargeting("x86")), targetedApexImage("apex/arm64-v8a.img", apexImageTargeting("arm64-v8a")), targetedApexImage("apex/armeabi-v7a.img", apexImageTargeting("armeabi-v7a")));
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile(APEX_MANIFEST_PATH, APEX_MANIFEST).addFile("apex/x86_64.img").addFile("apex/x86.img").addFile("apex/arm64-v8a.img").addFile("apex/armeabi-v7a.img").setApexConfig(apexConfig).setManifest(androidManifest("com.test.app", withTargetSdkVersion("Q.fingerprint"), withMinSdkVersion("Q.fingerprint")))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ImmutableSet<AbiAlias> x64Set = ImmutableSet.of(X86_64);
ImmutableSet<AbiAlias> x86Set = ImmutableSet.of(X86);
ImmutableSet<AbiAlias> arm8Set = ImmutableSet.of(ARM64_V8A);
ImmutableSet<AbiAlias> arm7Set = ImmutableSet.of(ARMEABI_V7A);
ImmutableSet<ImmutableSet<AbiAlias>> allTargeting = ImmutableSet.of(arm7Set, arm8Set, x86Set, x64Set);
ApkTargeting x64Targeting = apkMultiAbiTargetingFromAllTargeting(x64Set, allTargeting);
ApkTargeting x86Targeting = apkMultiAbiTargetingFromAllTargeting(x86Set, allTargeting);
ApkTargeting arm8Targeting = apkMultiAbiTargetingFromAllTargeting(arm8Set, allTargeting);
ApkTargeting arm7Targeting = apkMultiAbiTargetingFromAllTargeting(arm7Set, allTargeting);
ZipFile apkSetFile = new ZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
ImmutableMap<ApkTargeting, Variant> apexVariantsByAbi = extractApexVariantsByTargeting(result);
assertThat(apexVariantsByAbi.keySet()).containsExactly(x64Targeting, x86Targeting, arm8Targeting, arm7Targeting);
assertThat(apexVariantsByAbi.values().stream().map(variant -> variant.getTargeting().getSdkVersionTargeting()).collect(toImmutableSet())).containsExactly(sdkVersionTargeting(sdkVersionFrom(DEVELOPMENT_SDK_VERSION), ImmutableSet.of()));
}
use of com.android.bundle.Targeting.Abi.AbiAlias.X86 in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_splitApks_honorsMaxSdkVersion.
/**
* This test verifies uncompressed native libraries variant is not generated if not necessary.
*/
@Test
public void buildApksCommand_splitApks_honorsMaxSdkVersion() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("dex/classes.dex").addFile("lib/x86/libsome.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)))).setManifest(androidManifest("com.test.app", withMaxSdkVersion(21)))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(splitApkVariants(result)).hasSize(1);
Variant variant = splitApkVariants(result).get(0);
assertThat(variant.hasTargeting()).isTrue();
assertThat(variant.getTargeting().getSdkVersionTargeting().getValueList()).containsExactly(L_SDK_VERSION);
}
use of com.android.bundle.Targeting.Abi.AbiAlias.X86 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.AbiAlias.X86 in project bundletool by google.
the class BuildApksManagerTest method multipleModules_systemApks_hasCorrectAdditionalLanguageSplits.
@Test
@Theory
public void multipleModules_systemApks_hasCorrectAdditionalLanguageSplits() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.addFile("assets/base.txt").addFile("assets/languages#lang_es/image.jpg").addFile("assets/languages#lang_fr/image.jpg").setAssetsConfig(assets(targetedAssetsDirectory("assets/languages#lang_es", assetsDirectoryTargeting(languageTargeting("es"))), targetedAssetsDirectory("assets/languages#lang_fr", assetsDirectoryTargeting(languageTargeting("fr"))))).setManifest(androidManifest("com.app")).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("fused", module -> module.addFile("assets/fused.txt").addFile("assets/fused/languages#lang_es/image.jpg").addFile("assets/fused/languages#lang_fr/image.jpg").setAssetsConfig(assets(targetedAssetsDirectory("assets/fused/languages#lang_es", assetsDirectoryTargeting(languageTargeting("es"))), targetedAssetsDirectory("assets/fused/languages#lang_fr", assetsDirectoryTargeting(languageTargeting("fr"))))).setManifest(androidManifestForFeature("com.app", withFusingAttribute(true), withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withApkBuildMode(SYSTEM).withDeviceSpec(mergeSpecs(sdkVersion(28), abis("x86"), density(DensityAlias.MDPI), locales("es"))).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(systemApkVariants(result)).hasSize(1);
Variant systemVariant = result.getVariant(0);
assertThat(systemVariant.getVariantNumber()).isEqualTo(0);
assertThat(systemVariant.getApkSetList()).hasSize(1);
ApkSet baseApkSet = Iterables.getOnlyElement(systemVariant.getApkSetList());
assertThat(baseApkSet.getModuleMetadata().getName()).isEqualTo("base");
assertThat(baseApkSet.getApkDescriptionList()).hasSize(2);
assertThat(baseApkSet.getApkDescriptionList().stream().map(ApkDescription::getPath).collect(toImmutableSet())).containsExactly("system/system.apk", "splits/base-fr.apk");
baseApkSet.getApkDescriptionList().forEach(apkDescription -> assertThat(apkSetFile).hasFile(apkDescription.getPath()));
}
Aggregations