use of com.android.tools.build.bundletool.testing.AppBundleBuilder in project bundletool by google.
the class BuildApksManagerTest method selectsRightModules.
@Test
public void selectsRightModules() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.addFile("assets/base.txt").setManifest(androidManifest("com.app")).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("fused", module -> module.addFile("assets/fused.txt").setManifest(androidManifestForFeature("com.app", withFusingAttribute(true), withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).addModule("not_fused", module -> module.addFile("assets/not_fused.txt").setManifest(androidManifestForFeature("com.app", withFusingAttribute(false), withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
// Split APKs: All modules must be used.
ImmutableSet<String> modulesInSplitApks = splitApkVariants(result).stream().flatMap(variant -> variant.getApkSetList().stream()).map(ApkSet::getModuleMetadata).map(ModuleMetadata::getName).collect(toImmutableSet());
assertThat(modulesInSplitApks).containsExactly("base", "fused", "not_fused");
// Standalone APKs: Only base and modules marked for fusing must be used.
assertThat(standaloneApkVariants(result)).hasSize(1);
ImmutableList<ApkDescription> standaloneApks = apkDescriptions(standaloneApkVariants(result).get(0));
assertThat(standaloneApks).hasSize(1);
assertThat(standaloneApks.get(0).hasStandaloneApkMetadata()).isTrue();
assertThat(standaloneApks.get(0).getStandaloneApkMetadata().getFusedModuleNameList()).containsExactly("base", "fused");
File standaloneApkFile = extractFromApkSetFile(apkSetFile, standaloneApks.get(0).getPath(), outputDir);
// Validate that the standalone APK contains appropriate files.
ZipFile standaloneApkZip = openZipFile(standaloneApkFile);
assertThat(filesUnderPath(standaloneApkZip, ZipPath.create("assets"))).containsExactly("assets/base.txt", "assets/fused.txt");
}
use of com.android.tools.build.bundletool.testing.AppBundleBuilder in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_maxSdkVersion_createsExtraAlternative.
@Test
public void buildApksCommand_maxSdkVersion_createsExtraAlternative() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.app", withMinSdkVersion(21), withMaxSdkVersion(25)))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(result.getVariantList()).hasSize(1);
assertThat(standaloneApkVariants(result)).isEmpty();
assertThat(splitApkVariants(result)).hasSize(1);
assertThat(splitApkVariants(result).get(0).getTargeting()).isEqualTo(variantSdkTargeting(/* minSdkVersion= */
21, ImmutableSet.of(26)));
}
use of com.android.tools.build.bundletool.testing.AppBundleBuilder in project bundletool by google.
the class BuildApksManagerTest method multipleModulesFusedAndNotFused_systemApks_hasCorrectAdditionalLanguageSplits.
@Test
@Theory
public void multipleModulesFusedAndNotFused_systemApks_hasCorrectAdditionalLanguageSplits() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.addFile("assets/base.txt").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)))).addModule("notfused", module -> module.addFile("assets/notfused.txt").addFile("assets/notfused/languages#lang_it/image.jpg").setAssetsConfig(assets(targetedAssetsDirectory("assets/notfused/languages#lang_it", assetsDirectoryTargeting(languageTargeting("it"))))).setManifest(androidManifestForFeature("com.app", withFusingAttribute(false), 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(2);
ImmutableMap<String, ApkSet> apkSetByModule = Maps.uniqueIndex(systemVariant.getApkSetList(), apkSet -> apkSet.getModuleMetadata().getName());
assertThat(apkSetByModule.keySet()).containsExactly("base", "notfused");
ApkSet baseApkSet = apkSetByModule.get("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()));
ApkSet nonFusedApkSet = apkSetByModule.get("notfused");
assertThat(nonFusedApkSet.getApkDescriptionList()).hasSize(2);
assertThat(nonFusedApkSet.getApkDescriptionList().stream().map(ApkDescription::getPath).collect(toImmutableSet())).containsExactly("splits/notfused-master.apk", "splits/notfused-it.apk");
nonFusedApkSet.getApkDescriptionList().forEach(apkDescription -> assertThat(apkSetFile).hasFile(apkDescription.getPath()));
}
use of com.android.tools.build.bundletool.testing.AppBundleBuilder in project bundletool by google.
the class BuildApksManagerTest method mergeInstallTimeDisabled.
@Test
public void mergeInstallTimeDisabled() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("dex/classes.dex").setManifest(androidManifest("com.test.app"))).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(androidManifest("com.test.app", withInstallTimeDelivery(), withFusingAttribute(true), withInstallTimeRemovableElement(true)))).setBundleConfig(BundleConfigBuilder.create().setVersion("1.0.0").build()).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
ImmutableList<Variant> splitApkVariants = splitApkVariants(result);
assertThat(splitApkVariants).isNotEmpty();
assertThat(result.getPermanentlyFusedModulesList()).isEmpty();
for (Variant splitApkVariant : splitApkVariants(result)) {
assertThat(splitApkVariant.getApkSetList()).comparingElementsUsing(Correspondence.from((ApkSet apkSet, String moduleName) -> apkSet != null && apkSet.getModuleMetadata().getName().equals(moduleName), "equals")).containsExactly("base", "abi_feature");
}
}
use of com.android.tools.build.bundletool.testing.AppBundleBuilder in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_standalone_oneModuleOneVariant.
@Test
public void buildApksCommand_standalone_oneModuleOneVariant() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("dex/classes.dex").setManifest(androidManifest("com.test.app"))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(standaloneApkVariants(result)).hasSize(1);
Variant standaloneApkVariant = standaloneApkVariants(result).get(0);
assertThat(standaloneApkVariant.getApkSetList()).hasSize(1);
ApkSet shards = standaloneApkVariant.getApkSet(0);
assertThat(shards.getModuleMetadata().getName()).isEqualTo("base");
assertThat(shards.getApkDescriptionList()).hasSize(1);
assertThat(ZipPath.create(shards.getApkDescription(0).getPath()).getFileName()).isEqualTo(ZipPath.create("standalone.apk"));
assertThat(apkSetFile).hasFile(shards.getApkDescription(0).getPath());
}
Aggregations