use of com.android.tools.build.bundletool.testing.BundleModuleBuilder in project bundletool by google.
the class StandaloneApksGeneratorTest method shardByAbi_havingManyAbis_producesManyApks_withTransparency.
@Test
public void shardByAbi_havingManyAbis_producesManyApks_withTransparency() throws Exception {
TestComponent.useTestModule(this, TestModule.builder().withBundleConfig(bundleConfigNodexmergestrategy).withBundleMetadata(BUNDLE_METADATA_WITH_TRANSPARENCY).build());
BundleModule bundleModule = new BundleModuleBuilder("base").addFile("assets/file.txt").addFile("dex/classes.dex").addFile("lib/armeabi/libtest.so").addFile("lib/x86/libtest.so").addFile("lib/x86_64/libtest.so").addFile("res/drawable/image.jpg").addFile("res/drawable-mdpi/image.jpg").addFile("root/license.dat").setManifest(androidManifest("com.test.app")).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/armeabi", nativeDirectoryTargeting(ARMEABI)), targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)))).setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("image", ImmutableMap.of(DEFAULT_DENSITY_VALUE, "res/drawable/image.jpg", MDPI_VALUE, "res/drawable-mdpi/image.jpg")).build()).build();
ImmutableList<ModuleSplit> shards = standaloneApksGenerator.generateStandaloneApks(ImmutableList.of(bundleModule), standaloneApkOptimizations(OptimizationDimension.ABI));
assertThat(shards).hasSize(3);
assertThat(shards.stream().map(ModuleSplit::getSplitType).distinct().collect(toImmutableSet())).containsExactly(SplitType.STANDALONE);
VariantTargeting armVariantTargeting = mergeVariantTargeting(variantAbiTargeting(ARMEABI, ImmutableSet.of(X86, X86_64)), VARIANT_TARGETING_WITH_SDK_1);
VariantTargeting x86VariantTargeting = mergeVariantTargeting(variantAbiTargeting(X86, ImmutableSet.of(ARMEABI, X86_64)), VARIANT_TARGETING_WITH_SDK_1);
VariantTargeting x64VariantTargeting = mergeVariantTargeting(variantAbiTargeting(X86_64, ImmutableSet.of(ARMEABI, X86)), VARIANT_TARGETING_WITH_SDK_1);
assertThat(shards.stream().map(ModuleSplit::getVariantTargeting).distinct().collect(toImmutableSet())).containsExactly(armVariantTargeting, x64VariantTargeting, x86VariantTargeting);
for (ModuleSplit shard : shards) {
assertThat(extractPaths(shard.getEntries())).containsAtLeast("assets/file.txt", "dex/classes.dex", "res/drawable/image.jpg", "res/drawable-mdpi/image.jpg", "root/license.dat", "META-INF/code_transparency_signed.jwt");
}
}
use of com.android.tools.build.bundletool.testing.BundleModuleBuilder in project bundletool by google.
the class StandaloneApksGeneratorTest method shardByAbiAndDensity_havingNoAbiAndNoResources_producesOneApk.
@Test
public void shardByAbiAndDensity_havingNoAbiAndNoResources_producesOneApk() throws Exception {
BundleModule bundleModule = new BundleModuleBuilder("base").addFile("assets/file.txt").addFile("dex/classes.dex").addFile("root/license.dat").setManifest(androidManifest("com.test.app")).build();
ImmutableList<ModuleSplit> shards = standaloneApksGenerator.generateStandaloneApks(ImmutableList.of(bundleModule), standaloneApkOptimizations(OptimizationDimension.ABI, OptimizationDimension.SCREEN_DENSITY));
assertThat(shards).hasSize(1);
ModuleSplit fatShard = shards.get(0);
assertThat(fatShard.getApkTargeting()).isEqualToDefaultInstance();
assertThat(fatShard.getVariantTargeting()).isEqualTo(VARIANT_TARGETING_WITH_SDK_1);
assertThat(fatShard.getSplitType()).isEqualTo(SplitType.STANDALONE);
assertThat(extractPaths(fatShard.getEntries())).containsExactly("assets/file.txt", "dex/classes.dex", "root/license.dat");
}
use of com.android.tools.build.bundletool.testing.BundleModuleBuilder in project bundletool by google.
the class StandaloneApksGeneratorTest method manyModulesShardByDensity_havingOnlyOneDensityResource_producesSingleApk.
@Test
public void manyModulesShardByDensity_havingOnlyOneDensityResource_producesSingleApk() throws Exception {
BundleModule baseModule = new BundleModuleBuilder("base").addFile("res/drawable-hdpi/image.jpg").setManifest(androidManifest("com.test.app")).setResourceTable(resourceTable(pkg(USER_PACKAGE_OFFSET, "com.test.app", type(0x01, "drawable", entry(0x01, "image", fileReference("res/drawable-hdpi/image.jpg", HDPI)))))).build();
BundleModule featureModule = new BundleModuleBuilder("feature").addFile("res/drawable-hdpi/image2.jpg").setManifest(androidManifestForFeature("com.test.app")).setResourceTable(resourceTable(pkg(USER_PACKAGE_OFFSET + 1, "com.test.app.split", type(0x01, "drawable", entry(0x01, "image2", fileReference("res/drawable-hdpi/image2.jpg", HDPI)))))).build();
ImmutableList<ModuleSplit> shards = standaloneApksGenerator.generateStandaloneApks(ImmutableList.of(baseModule, featureModule), standaloneApkOptimizations(OptimizationDimension.SCREEN_DENSITY));
assertThat(shards).hasSize(1);
ModuleSplit shard = shards.get(0);
assertThat(extractPaths(shard.findEntriesUnderPath("res"))).containsExactly("res/drawable-hdpi/image.jpg", "res/drawable-hdpi/image2.jpg");
assertThat(shard.getResourceTable().get()).containsResource("com.test.app:drawable/image").withConfigSize(1);
assertThat(shard.getResourceTable().get()).containsResource("com.test.app.split:drawable/image2").withConfigSize(1);
assertThat(shard.getApkTargeting()).isEqualToDefaultInstance();
}
use of com.android.tools.build.bundletool.testing.BundleModuleBuilder in project bundletool by google.
the class StandaloneApksGeneratorTest method manyModulesShardByAbi_havingSingleAbi_producesOneApk.
@Test
public void manyModulesShardByAbi_havingSingleAbi_producesOneApk() throws Exception {
BundleModule baseModule = new BundleModuleBuilder("base").addFile("dex/classes.dex").addFile("root/license.dat").setManifest(androidManifest("com.test.app")).build();
BundleModule featureModule1 = new BundleModuleBuilder("feature1").addFile("lib/x86_64/lib1.so").setManifest(androidManifest("com.test.app")).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)))).build();
BundleModule featureModule2 = new BundleModuleBuilder("feature2").addFile("lib/x86_64/lib2.so").setManifest(androidManifest("com.test.app")).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)))).build();
ImmutableList<ModuleSplit> shards = standaloneApksGenerator.generateStandaloneApks(ImmutableList.of(baseModule, featureModule1, featureModule2), standaloneApkOptimizations(OptimizationDimension.ABI));
assertThat(shards).hasSize(1);
ModuleSplit shard = shards.get(0);
assertThat(shard.getApkTargeting()).isEqualTo(apkAbiTargeting(X86_64));
assertThat(shard.getVariantTargeting()).isEqualTo(mergeVariantTargeting(variantAbiTargeting(X86_64), VARIANT_TARGETING_WITH_SDK_1));
assertThat(shard.getSplitType()).isEqualTo(SplitType.STANDALONE);
assertThat(extractPaths(shard.getEntries())).containsExactly("dex/classes.dex", "lib/x86_64/lib1.so", "lib/x86_64/lib2.so", "root/license.dat");
}
use of com.android.tools.build.bundletool.testing.BundleModuleBuilder in project bundletool by google.
the class StandaloneApksGeneratorTest method manyModulesShardByAbiAndDensity_havingManyAbisAndSomeResource_producesManyApks.
@Test
public void manyModulesShardByAbiAndDensity_havingManyAbisAndSomeResource_producesManyApks() throws Exception {
BundleModule baseModule = new BundleModuleBuilder("base").addFile("assets/file.txt").addFile("dex/classes.dex").addFile("res/drawable/image.jpg").addFile("res/drawable-hdpi/image.jpg").addFile("root/license.dat").setManifest(androidManifest("com.test.app")).setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("image", ImmutableMap.of(DEFAULT_DENSITY_VALUE, "res/drawable/image.jpg", HDPI_VALUE, "res/drawable-hdpi/image.jpg")).build()).build();
BundleModule featureModule = new BundleModuleBuilder("feature").addFile("lib/armeabi/libtest.so").addFile("lib/x86/libtest.so").setManifest(androidManifest("com.test.app")).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/armeabi", nativeDirectoryTargeting(ARMEABI)), targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)))).build();
ImmutableList<ModuleSplit> shards = standaloneApksGenerator.generateStandaloneApks(ImmutableList.of(baseModule, featureModule), standaloneApkOptimizations(OptimizationDimension.ABI, OptimizationDimension.SCREEN_DENSITY));
assertThat(shards).hasSize(2 * 7);
assertThat(shards.stream().map(ModuleSplit::getSplitType).distinct().collect(toImmutableSet())).containsExactly(SplitType.STANDALONE);
ApkTargeting armTargeting = apkAbiTargeting(ARMEABI, ImmutableSet.of(X86));
ApkTargeting x86Targeting = apkAbiTargeting(X86, ImmutableSet.of(ARMEABI));
assertThat(shards.stream().map(ModuleSplit::getApkTargeting).collect(toImmutableList())).ignoringRepeatedFieldOrder().containsExactly(mergeApkTargeting(armTargeting, LDPI_TARGETING), mergeApkTargeting(armTargeting, MDPI_TARGETING), mergeApkTargeting(armTargeting, HDPI_TARGETING), mergeApkTargeting(armTargeting, XHDPI_TARGETING), mergeApkTargeting(armTargeting, XXHDPI_TARGETING), mergeApkTargeting(armTargeting, XXXHDPI_TARGETING), mergeApkTargeting(armTargeting, TVDPI_TARGETING), mergeApkTargeting(x86Targeting, LDPI_TARGETING), mergeApkTargeting(x86Targeting, MDPI_TARGETING), mergeApkTargeting(x86Targeting, HDPI_TARGETING), mergeApkTargeting(x86Targeting, XHDPI_TARGETING), mergeApkTargeting(x86Targeting, XXHDPI_TARGETING), mergeApkTargeting(x86Targeting, XXXHDPI_TARGETING), mergeApkTargeting(x86Targeting, TVDPI_TARGETING));
// Check files not specific to ABI nor screen density.
for (ModuleSplit shard : shards) {
assertThat(extractPaths(shard.getEntries())).containsAtLeast("assets/file.txt", "dex/classes.dex", "root/license.dat");
}
// Check resources.
for (ModuleSplit shard : shards) {
DensityAlias density = shard.getApkTargeting().getScreenDensityTargeting().getValueList().get(0).getDensityAlias();
switch(density) {
case LDPI:
case MDPI:
assertThat(extractPaths(shard.findEntriesUnderPath("res/"))).containsExactly("res/drawable/image.jpg");
assertThat(shard.getResourceTable().get()).containsResource("com.test.app:drawable/image").onlyWithConfigs(Configuration.getDefaultInstance());
break;
case TVDPI:
// TVDPI is a special case because the bucket encompasses devices that could serve either
// the MDPI or the HDPI resource, so both resources are present.
assertThat(extractPaths(shard.findEntriesUnderPath("res/"))).containsExactly("res/drawable/image.jpg", "res/drawable-hdpi/image.jpg");
assertThat(shard.getResourceTable().get()).containsResource("com.test.app:drawable/image").onlyWithConfigs(Configuration.getDefaultInstance(), HDPI);
break;
case HDPI:
case XHDPI:
case XXHDPI:
case XXXHDPI:
assertThat(extractPaths(shard.findEntriesUnderPath("res/"))).containsExactly("res/drawable-hdpi/image.jpg");
assertThat(shard.getResourceTable().get()).containsResource("com.test.app:drawable/image").onlyWithConfigs(HDPI);
break;
default:
fail("Unexpected screen density targeting: " + density);
}
}
// Check native libraries.
for (ModuleSplit shard : shards) {
switch(shard.getApkTargeting().getAbiTargeting().getValue(0).getAlias()) {
case ARMEABI:
assertThat(extractPaths(shard.getEntries())).contains("lib/armeabi/libtest.so");
assertThat(extractPaths(shard.getEntries())).containsNoneOf("lib/x86/libtest.so", "lib/x86_64/libtest.so");
break;
case X86:
assertThat(extractPaths(shard.getEntries())).contains("lib/x86/libtest.so");
assertThat(extractPaths(shard.getEntries())).containsNoneOf("lib/armeabi/libtest.so", "lib/x86_64/libtest.so");
break;
default:
fail("Unexpected ABI targeting in: " + shard.getApkTargeting());
}
}
}
Aggregations