use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_standalone_textureTargetingWithSuffixStripped.
@Test
public void buildApksCommand_standalone_textureTargetingWithSuffixStripped() 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#tcf_atc/texture.dat").addFile("assets/textures#tcf_etc1/texture.dat").setAssetsConfig(assets(targetedAssetsDirectory("assets/textures#tcf_atc", assetsDirectoryTargeting(textureCompressionTargeting(ATC))), 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, /* stripSuffix= */
true, /* defaultSuffix= */
"etc1").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))) {
assertThat(shardZip).hasFile("assets/textures/texture.dat");
assertThat(shardZip).doesNotHaveFile("assets/textures#tcf_atc/texture.dat");
assertThat(shardZip).doesNotHaveFile("assets/textures#tcf_etc1/texture.dat");
}
// Check that targeting was applied to both the APK and the variant
assertThat(standaloneApkVariants(result).get(0).getTargeting().getTextureCompressionFormatTargeting().getValueList()).containsExactly(textureCompressionFormat(ETC1_RGB8));
assertThat(shard.getTargeting().getTextureCompressionFormatTargeting().getValueList()).containsExactly(textureCompressionFormat(ETC1_RGB8));
}
use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_universal_mergeActivitiesFromFeatureManifest_0_13_4.
@Test
public void buildApksCommand_universal_mergeActivitiesFromFeatureManifest_0_13_4() throws Exception {
final int baseThemeRefId = 123;
final int featureThemeRefId = 4456;
AppBundle appBundle = new AppBundleBuilder().setBundleConfig(BundleConfig.newBuilder().setBundletool(Bundletool.newBuilder().setVersion("0.13.4")).build()).addModule("base", builder -> builder.setManifest(androidManifest("com.test.app", withCustomThemeActivity("activity1", baseThemeRefId), withCustomThemeActivity("activity2", baseThemeRefId))).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("feature", builder -> builder.setManifest(androidManifestForFeature("com.test.app.feature1", withFusingAttribute(true), withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID), withCustomThemeActivity("activity1", featureThemeRefId), withSplitNameService("service1", "feature")))).addModule("not_fused", builder -> builder.setManifest(androidManifestForFeature("com.test.app.feature2", withFusingAttribute(false), withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID), withCustomThemeActivity("activity2", featureThemeRefId), withSplitNameService("service2", "not_fused")))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withApkBuildMode(UNIVERSAL).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
Variant universalVariant = standaloneApkVariants(result).get(0);
assertThat(apkDescriptions(universalVariant)).hasSize(1);
ApkDescription universalApk = apkDescriptions(universalVariant).get(0);
// Correct modules selected for merging.
assertThat(universalApk.getStandaloneApkMetadata().getFusedModuleNameList()).containsExactly("base", "feature");
File universalApkFile = extractFromApkSetFile(apkSetFile, universalApk.getPath(), outputDir);
AndroidManifest manifest = extractAndroidManifest(universalApkFile, tmpDir);
Map<String, Integer> refIdByActivity = transformValues(manifest.getActivitiesByName(), activity -> activity.getAndroidAttribute(AndroidManifest.THEME_RESOURCE_ID).get().getValueAsRefId());
assertThat(refIdByActivity).containsExactly("activity1", featureThemeRefId, "activity2", baseThemeRefId);
assertThat(getServicesFromManifest(manifest)).isEmpty();
}
use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_standalone_mixedTargeting.
@Test
public void buildApksCommand_standalone_mixedTargeting() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.test.app")).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("feature_abi_lib", builder -> builder.addFile("lib/x86/libfeature.so").addFile("lib/x86_64/libfeature.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("feature_lang_assets", builder -> builder.addFile("assets/strings#lang_en/trans.txt").addFile("assets/strings#lang_fr/trans.txt").setAssetsConfig(assets(targetedAssetsDirectory("assets/strings#lang_en", assetsDirectoryTargeting(languageTargeting("en"))), targetedAssetsDirectory("assets/strings#lang_fr", assetsDirectoryTargeting(languageTargeting("fr"))))).setManifest(androidManifestForFeature("com.test.app", withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).addModule("feature_tcf_assets", builder -> builder.addFile("assets/textures#tcf_atc/texture.dat").addFile("assets/textures#tcf_etc1/texture.dat").setAssetsConfig(assets(targetedAssetsDirectory("assets/textures#tcf_atc", assetsDirectoryTargeting(textureCompressionTargeting(ATC))), targetedAssetsDirectory("assets/textures#tcf_etc1", assetsDirectoryTargeting(textureCompressionTargeting(ETC1_RGB8))))).setManifest(androidManifestForFeature("com.test.app", withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).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, ApkDescription> standaloneApksByAbi = Maps.uniqueIndex(apkDescriptions(standaloneApkVariants(result)), apkDesc -> getOnlyElement(apkDesc.getTargeting().getAbiTargeting().getValueList()));
assertThat(standaloneApksByAbi.keySet()).containsExactly(toAbi(X86), toAbi(X86_64));
File x86ApkFile = extractFromApkSetFile(apkSetFile, standaloneApksByAbi.get(toAbi(X86)).getPath(), outputDir);
try (ZipFile x86Zip = new ZipFile(x86ApkFile)) {
// ABI-specific files.
assertThat(x86Zip).hasFile("lib/x86/libfeature.so");
assertThat(x86Zip).doesNotHaveFile("lib/x86_64/libfeature.so");
// Included in each standalone APK.
assertThat(x86Zip).hasFile("assets/strings#lang_en/trans.txt");
assertThat(x86Zip).hasFile("assets/strings#lang_fr/trans.txt");
assertThat(x86Zip).hasFile("assets/textures#tcf_atc/texture.dat");
assertThat(x86Zip).hasFile("assets/textures#tcf_etc1/texture.dat");
}
File x64ApkFile = extractFromApkSetFile(apkSetFile, standaloneApksByAbi.get(toAbi(X86_64)).getPath(), outputDir);
try (ZipFile x64Zip = new ZipFile(x64ApkFile)) {
// ABI-specific files.
assertThat(x64Zip).hasFile("lib/x86_64/libfeature.so");
assertThat(x64Zip).doesNotHaveFile("lib/x86/libfeature.so");
// Included in each standalone APK.
assertThat(x64Zip).hasFile("assets/strings#lang_en/trans.txt");
assertThat(x64Zip).hasFile("assets/strings#lang_fr/trans.txt");
assertThat(x64Zip).hasFile("assets/textures#tcf_atc/texture.dat");
assertThat(x64Zip).hasFile("assets/textures#tcf_etc1/texture.dat");
}
}
use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_minSdkVersion_presentInStandaloneSdkTargeting.
@Test
public void buildApksCommand_minSdkVersion_presentInStandaloneSdkTargeting() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.app", withMinSdkVersion(15), withMaxSdkVersion(20)))).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(splitApkVariants(result)).isEmpty();
assertThat(standaloneApkVariants(result)).hasSize(1);
assertThat(standaloneApkVariants(result).get(0).getTargeting()).isEqualTo(variantSdkTargeting(/* minSdkVersion= */
15, ImmutableSet.of(21)));
}
use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_universal_withAssetModules.
@Test
public void buildApksCommand_universal_withAssetModules() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("lib/x86/libsome.so").setManifest(androidManifest("com.test.app"))).addModule("upfront_asset_module", builder -> builder.addFile("assets/upfront_asset.jpg").setManifest(androidManifestForAssetModule("com.test.app", withInstallTimeDelivery()))).addModule("on_demand_asset_module", builder -> builder.addFile("assets/on_demand_asset.jpg").setManifest(androidManifestForAssetModule("com.test.app", withOnDemandDelivery()))).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(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();
File universalApkFile = extractFromApkSetFile(apkSetFile, universalApk.getPath(), outputDir);
try (ZipFile universalApkZipFile = new ZipFile(universalApkFile)) {
assertThat(filesUnderPath(universalApkZipFile, ZipPath.create("lib"))).containsExactly("lib/x86/libsome.so");
assertThat(filesUnderPath(universalApkZipFile, ZipPath.create("assets"))).containsExactly("assets/upfront_asset.jpg");
}
}
Aggregations