use of com.android.tools.build.bundletool.testing.ResourceTableBuilder 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());
}
}
}
use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.
the class SystemApksGeneratorTest method manyModulesShardByAbiAndDensity_havingManyAbisAndSomeResourceWithDeviceSpec_producesSingleApk.
@Test
public void manyModulesShardByAbiAndDensity_havingManyAbisAndSomeResourceWithDeviceSpec_producesSingleApk() 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(androidManifestForFeature("com.test.app")).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/armeabi", nativeDirectoryTargeting(ARMEABI)), targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)))).build();
ImmutableList<ModuleSplit> shards = systemApksGenerator.generateSystemApks(/* modules= */
ImmutableList.of(baseModule, featureModule), /* modulesToFuse= */
ImmutableSet.of(BASE_MODULE_NAME, FEATURE_MODULE_NAME), splitOptimizations(OptimizationDimension.ABI, OptimizationDimension.SCREEN_DENSITY));
ModuleSplit fatShard = getSystemImageSplit(shards);
assertThat(fatShard.getApkTargeting().getAbiTargeting()).isEqualTo(abiTargeting(X86, ImmutableSet.of(ARMEABI)));
assertThat(fatShard.getApkTargeting().getScreenDensityTargeting().getValueList()).containsExactly(toScreenDensity(DensityAlias.MDPI));
assertThat(fatShard.getSplitType()).isEqualTo(SplitType.SYSTEM);
assertThat(fatShard.isBaseModuleSplit()).isTrue();
assertThat(extractPaths(fatShard.getEntries())).containsExactly("assets/file.txt", "dex/classes.dex", "lib/x86/libtest.so", "res/drawable/image.jpg", "root/license.dat");
assertThat(shards).hasSize(1);
}
use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.
the class SystemApksGeneratorTest method shardByAbi_havingSingleAbi_producesOneApk.
@Test
public void shardByAbi_havingSingleAbi_producesOneApk() throws Exception {
BundleModule bundleModule = new BundleModuleBuilder("base").addFile("assets/file.txt").addFile("dex/classes.dex").addFile("lib/x86/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/x86", nativeDirectoryTargeting(X86)))).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 = systemApksGenerator.generateSystemApks(/* modules= */
ImmutableList.of(bundleModule), /* modulesToFuse= */
ImmutableSet.of(BASE_MODULE_NAME), splitOptimizations(OptimizationDimension.ABI));
assertThat(shards).hasSize(1);
ModuleSplit fatShard = shards.get(0);
assertThat(fatShard.getApkTargeting()).isEqualTo(apkAbiTargeting(X86));
assertThat(fatShard.getVariantTargeting()).isEqualTo(mergeVariantTargeting(variantMinSdkTargeting(1), variantAbiTargeting(X86)));
assertThat(fatShard.getSplitType()).isEqualTo(SplitType.SYSTEM);
assertThat(extractPaths(fatShard.getEntries())).containsExactly("assets/file.txt", "dex/classes.dex", "lib/x86/libtest.so", "res/drawable/image.jpg", "res/drawable-mdpi/image.jpg", "root/license.dat");
}
use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.
the class ShardedApksFacadeTest method singleModule_withNativeLibsAndDensityWithDeviceSpec_64bitNativeLibsDisabled.
@Test
public void singleModule_withNativeLibsAndDensityWithDeviceSpec_64bitNativeLibsDisabled() throws Exception {
TestComponent.useTestModule(this, TestModule.builder().withDeviceSpec(mergeSpecs(sdkVersion(28), abis("x86"), density(DensityAlias.MDPI), locales("en-US"))).withBundleConfig(BundleConfig.newBuilder().setOptimizations(Optimizations.newBuilder().setStandaloneConfig(StandaloneConfig.newBuilder().setStrip64BitLibraries(true)))).build());
ImmutableList<BundleModule> bundleModule = ImmutableList.of(new BundleModuleBuilder("base").addFile("lib/x86/libsome.so").addFile("lib/x86_64/libsome.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(AbiAlias.X86_64)))).addFile("res/drawable-ldpi/image.jpg").addFile("res/drawable-mdpi/image.jpg").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("image", ImmutableMap.of(LDPI_VALUE, "res/drawable-ldpi/image.jpg", MDPI_VALUE, "res/drawable-mdpi/image.jpg")).build()).setManifest(androidManifest("com.test.app")).build());
ImmutableList<ModuleSplit> moduleSplits = shardedApksFacade.generateSystemSplits(/* modules= */
bundleModule, /* modulesToFuse= */
ImmutableSet.of(BASE_MODULE_NAME), DEFAULT_APK_OPTIMIZATIONS);
// 1 (density), 1 (abi) split
assertThat(moduleSplits).hasSize(1);
ModuleSplit moduleSplit = moduleSplits.get(0);
assertThat(moduleSplit.getApkTargeting().getAbiTargeting()).isEqualTo(abiTargeting(X86));
assertThat(moduleSplit.getApkTargeting().getScreenDensityTargeting().getValueList()).containsExactly(toScreenDensity(DensityAlias.MDPI));
assertThat(moduleSplits.stream().map(ModuleSplit::getSplitType).collect(toImmutableSet())).containsExactly(SplitType.SYSTEM);
assertThat(moduleSplit.isMasterSplit()).isTrue();
}
use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.
the class StandaloneApksGeneratorTest method shardByDensity_havingNonDensityResources_producesOneApk.
@Test
public void shardByDensity_havingNonDensityResources_producesOneApk() throws Exception {
ResourceTable resourceTable = new ResourceTableBuilder().addPackage("com.test.app").addFileResourceForMultipleConfigs("drawable", "image", ImmutableMap.of(Configuration.getDefaultInstance(), "res/drawable/image.jpg", locale("de"), "res/drawable-de/image.jpg")).build();
BundleModule bundleModule = new BundleModuleBuilder("base").addFile("assets/file.txt").addFile("dex/classes.dex").addFile("lib/x86/libtest.so").addFile("res/drawable/image.jpg").addFile("res/drawable-de/image.jpg").addFile("root/license.dat").setManifest(androidManifest("com.test.app")).setResourceTable(resourceTable).build();
ImmutableList<ModuleSplit> shards = standaloneApksGenerator.generateStandaloneApks(ImmutableList.of(bundleModule), standaloneApkOptimizations(OptimizationDimension.SCREEN_DENSITY));
assertThat(shards).hasSize(1);
ModuleSplit shard = shards.get(0);
assertThat(extractPaths(shard.getEntries())).containsExactly("assets/file.txt", "dex/classes.dex", "lib/x86/libtest.so", "res/drawable/image.jpg", "res/drawable-de/image.jpg", "root/license.dat");
assertThat((Message) shard.getResourceTable().get()).ignoringRepeatedFieldOrder().isEqualTo(resourceTable);
assertThat(shard.getApkTargeting()).isEqualToDefaultInstance();
assertThat(shard.getVariantTargeting()).isEqualTo(VARIANT_TARGETING_WITH_SDK_1);
assertThat(shard.getSplitType()).isEqualTo(SplitType.STANDALONE);
ImmutableList<ApkTargeting> targetings = shards.stream().map(ModuleSplit::getApkTargeting).collect(toImmutableList());
assertThat(targetings).containsNoDuplicates();
assertThat(targetings).ignoringRepeatedFieldOrder().containsExactly(ApkTargeting.getDefaultInstance());
}
Aggregations