use of com.android.bundle.Commands.ApkDescription in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_universal_generatesSingleApkWithSingleFallbackTcf.
@Test
public void buildApksCommand_universal_generatesSingleApkWithSingleFallbackTcf() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.test.app"))).addModule("tcf_assets", builder -> builder.addFile("assets/textures/fallback_texture.dat").addFile("assets/textures#tcf_etc1/etc1_texture.dat").setAssetsConfig(assets(targetedAssetsDirectory("assets/textures", assetsDirectoryTargeting(alternativeTextureCompressionTargeting(ETC1_RGB8))), targetedAssetsDirectory("assets/textures#tcf_etc1", assetsDirectoryTargeting(textureCompressionTargeting(ETC1_RGB8))))).setManifest(androidManifestForAssetModule("com.test.app", withInstallTimeDelivery()))).setBundleConfig(BundleConfigBuilder.create().addSplitDimension(Value.TEXTURE_COMPRESSION_FORMAT).build()).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withApkBuildMode(UNIVERSAL).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(standaloneApkVariants(result)).hasSize(1);
Variant universalVariant = standaloneApkVariants(result).get(0);
assertThat(apkDescriptions(universalVariant)).hasSize(1);
ApkDescription universalApk = apkDescriptions(universalVariant).get(0);
// Check APK content
File universalApkFile = extractFromApkSetFile(apkSetFile, universalApk.getPath(), outputDir);
try (ZipFile universalApkZipFile = new ZipFile(universalApkFile)) {
// Only the requested format texture is included in the standalone APK.
// Even if suffix stripping is not activated, the universal APK must only contain one TCF.
assertThat(filesUnderPath(universalApkZipFile, ASSETS_DIRECTORY)).containsExactly("assets/textures/fallback_texture.dat");
}
}
use of com.android.bundle.Commands.ApkDescription in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_standalone_mixedTextureTargeting.
@Test
public void buildApksCommand_standalone_mixedTextureTargeting() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.test.app")).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("feature_tcf_assets", builder -> builder.addFile("assets/textures/untargeted_texture.dat").addFile("assets/textures#tcf_etc1/etc1_texture.dat").setAssetsConfig(assets(targetedAssetsDirectory("assets/textures", assetsDirectoryTargeting(alternativeTextureCompressionTargeting(ETC1_RGB8))), targetedAssetsDirectory("assets/textures#tcf_etc1", assetsDirectoryTargeting(textureCompressionTargeting(ETC1_RGB8))))).setManifest(androidManifestForFeature("com.test.app", withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).setBundleConfig(BundleConfigBuilder.create().addSplitDimension(Value.TEXTURE_COMPRESSION_FORMAT, /* negate= */
false).build()).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withOptimizationDimensions(TEXTURE_COMPRESSION_FORMAT).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(standaloneApkVariants(result)).hasSize(1);
assertThat(apkDescriptions(standaloneApkVariants(result))).hasSize(1);
ApkDescription shard = apkDescriptions(standaloneApkVariants(result)).get(0);
// Check APK content
assertThat(apkSetFile).hasFile(shard.getPath());
try (ZipFile shardZip = new ZipFile(extractFromApkSetFile(apkSetFile, shard.getPath(), outputDir))) {
// Only the default format texture is included in the standalone APK.
// Even if suffix stripping is not activated, the standalone APK must only contain one TCF.
assertThat(shardZip).hasFile("assets/textures/untargeted_texture.dat");
assertThat(shardZip).doesNotHaveFile("assets/textures#tcf_etc1/texture.dat");
}
}
use of com.android.bundle.Commands.ApkDescription in project bundletool by google.
the class BuildApksManagerTest method deviceTieredAssets_withDeviceSpec_deviceTierSet.
@Test
public void deviceTieredAssets_withDeviceSpec_deviceTierSet() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("assets/images#tier_0/image.jpg").addFile("assets/images#tier_1/image.jpg").setManifest(androidManifest("com.test.app")).setAssetsConfig(assets(targetedAssetsDirectory("assets/images#tier_0", assetsDirectoryTargeting(deviceTierTargeting(/* value= */
0, /* alternatives= */
ImmutableList.of(1)))), targetedAssetsDirectory("assets/images#tier_1", assetsDirectoryTargeting(deviceTierTargeting(/* value= */
1, /* alternatives= */
ImmutableList.of(0))))))).setBundleConfig(BundleConfigBuilder.create().addSplitDimension(Value.DEVICE_TIER, /* negate= */
false, /* stripSuffix= */
false, /* defaultSuffix= */
"0").build()).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withDeviceSpec(mergeSpecs(sdkVersion(29), abis("x86"), density(DensityAlias.MDPI), locales("en-US"), deviceTier(1))).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
ImmutableList<Variant> splitApkVariants = splitApkVariants(result);
ImmutableList<ApkDescription> splitApks = apkDescriptions(splitApkVariants);
// Check that only an APK for tier 1 has been created, not for 0
ImmutableList<ApkDescription> deviceTierSplits = splitApks.stream().filter(apkDesc -> apkDesc.getTargeting().hasDeviceTierTargeting()).collect(toImmutableList());
assertThat(apkNamesInApkDescriptions(deviceTierSplits)).containsExactly("base-tier_1.apk");
// Check the content of the APK
ImmutableMap<DeviceTierTargeting, ApkDescription> deviceTierSplitsByTargeting = Maps.uniqueIndex(deviceTierSplits, apk -> apk.getTargeting().getDeviceTierTargeting());
ApkDescription mediumTierSplit = deviceTierSplitsByTargeting.get(deviceTierTargeting(/* value= */
1, /* alternatives= */
ImmutableList.of(0)));
assertThat(filesInApk(mediumTierSplit, apkSetFile)).contains("assets/images#tier_1/image.jpg");
}
use of com.android.bundle.Commands.ApkDescription 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.bundle.Commands.ApkDescription 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()));
}
Aggregations