use of com.android.bundle.Targeting.ApkTargeting in project bundletool by google.
the class StandaloneApksGeneratorTest method shardByAbiAndDensity_havingManyAbisAndSomeResource_producesManyApks.
@Test
public void shardByAbiAndDensity_havingManyAbisAndSomeResource_producesManyApks() throws Exception {
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-ldpi/image.jpg").addFile("res/drawable-hdpi/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(LDPI_VALUE, "res/drawable-ldpi/image.jpg", HDPI_VALUE, "res/drawable-hdpi/image.jpg")).build()).build();
ImmutableList<ModuleSplit> shards = standaloneApksGenerator.generateStandaloneApks(ImmutableList.of(bundleModule), standaloneApkOptimizations(OptimizationDimension.ABI, OptimizationDimension.SCREEN_DENSITY));
assertThat(shards).hasSize(3 * 7);
assertThat(shards.stream().map(ModuleSplit::getSplitType).distinct().collect(toImmutableSet())).containsExactly(SplitType.STANDALONE);
ApkTargeting armTargeting = apkAbiTargeting(ARMEABI, ImmutableSet.of(X86, X86_64));
ApkTargeting x86Targeting = apkAbiTargeting(X86, ImmutableSet.of(ARMEABI, X86_64));
ApkTargeting x64Targeting = apkAbiTargeting(X86_64, ImmutableSet.of(ARMEABI, X86));
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), mergeApkTargeting(x64Targeting, LDPI_TARGETING), mergeApkTargeting(x64Targeting, MDPI_TARGETING), mergeApkTargeting(x64Targeting, HDPI_TARGETING), mergeApkTargeting(x64Targeting, XHDPI_TARGETING), mergeApkTargeting(x64Targeting, XXHDPI_TARGETING), mergeApkTargeting(x64Targeting, XXXHDPI_TARGETING), mergeApkTargeting(x64Targeting, 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().getValue(0).getDensityAlias();
switch(density) {
case LDPI:
assertThat(extractPaths(shard.findEntriesUnderPath("res"))).containsExactly("res/drawable-ldpi/image.jpg");
assertThat(shard.getResourceTable().get()).containsResource("com.test.app:drawable/image").onlyWithConfigs(LDPI);
break;
case MDPI:
// MDPI is a special case because the bucket encompasses devices that could serve either
// the LDPI or the HDPI resource, so both resources are present.
assertThat(extractPaths(shard.findEntriesUnderPath("res"))).containsExactly("res/drawable-ldpi/image.jpg", "res/drawable-hdpi/image.jpg");
assertThat(shard.getResourceTable().get()).containsResource("com.test.app:drawable/image").onlyWithConfigs(LDPI, HDPI);
break;
case TVDPI:
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 targeting density: " + 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;
case X86_64:
assertThat(extractPaths(shard.getEntries())).contains("lib/x86_64/libtest.so");
assertThat(extractPaths(shard.getEntries())).containsNoneOf("lib/armeabi/libtest.so", "lib/x86/libtest.so");
break;
default:
fail("Unexpected ABI targeting in: " + shard.getApkTargeting());
}
}
}
use of com.android.bundle.Targeting.ApkTargeting in project bundletool by google.
the class StandaloneApksGeneratorTest method shardByAbi_havingManyAbis_producesManyApks.
@Test
public void shardByAbi_havingManyAbis_producesManyApks() throws Exception {
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");
}
ApkTargeting armTargeting = apkAbiTargeting(ARMEABI, ImmutableSet.of(X86, X86_64));
ApkTargeting x86Targeting = apkAbiTargeting(X86, ImmutableSet.of(ARMEABI, X86_64));
ApkTargeting x64Targeting = apkAbiTargeting(X86_64, ImmutableSet.of(ARMEABI, X86));
ImmutableMap<ApkTargeting, ModuleSplit> shardsByTargeting = Maps.uniqueIndex(shards, ModuleSplit::getApkTargeting);
assertThat(shardsByTargeting.keySet()).containsExactly(armTargeting, x86Targeting, x64Targeting);
assertThat(extractPaths(shardsByTargeting.get(armTargeting).getEntries())).contains("lib/armeabi/libtest.so");
assertThat(extractPaths(shardsByTargeting.get(armTargeting).getEntries())).containsNoneOf("lib/x86/libtest.so", "lib/x86_64/libtest.so");
assertThat(extractPaths(shardsByTargeting.get(x86Targeting).getEntries())).contains("lib/x86/libtest.so");
assertThat(extractPaths(shardsByTargeting.get(x86Targeting).getEntries())).containsNoneOf("lib/armeabi/libtest.so", "lib/x86_64/libtest.so");
assertThat(extractPaths(shardsByTargeting.get(x64Targeting).getEntries())).contains("lib/x86_64/libtest.so");
assertThat(extractPaths(shardsByTargeting.get(x64Targeting).getEntries())).containsNoneOf("lib/armeabi/libtest.so", "lib/x86/libtest.so");
}
use of com.android.bundle.Targeting.ApkTargeting in project bundletool by google.
the class ScreenDensityResourcesSplitterTest method allSplitsPresentWithResourceTable.
@Test
public void allSplitsPresentWithResourceTable() throws Exception {
BundleModule testModule = new BundleModuleBuilder("testModule").addFile("res/drawable-mdpi/image.jpg").addFile("res/drawable-hdpi/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();
ImmutableSet<DensityAlias> densities = ImmutableSet.of(DensityAlias.LDPI, DensityAlias.MDPI, DensityAlias.TVDPI, DensityAlias.HDPI, DensityAlias.XHDPI, DensityAlias.XXHDPI, DensityAlias.XXXHDPI);
ImmutableCollection<ModuleSplit> densitySplits = splitter.split(ModuleSplit.forResources(testModule));
for (ModuleSplit resourceSplit : densitySplits) {
assertThat(resourceSplit.getResourceTable().isPresent()).isTrue();
}
List<ApkTargeting> targeting = densitySplits.stream().map(split -> split.getApkTargeting()).collect(Collectors.toList());
assertThat(targeting).ignoringRepeatedFieldOrder().containsExactly(ApkTargeting.getDefaultInstance(), apkDensityTargeting(DensityAlias.LDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.LDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.MDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.MDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.HDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.HDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.XHDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.XHDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.XXHDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.XXHDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.XXXHDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.XXXHDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.TVDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.TVDPI))));
}
use of com.android.bundle.Targeting.ApkTargeting in project bundletool by google.
the class ProtoFuzzerTest method randomProtoMessage_messageFieldPopulated.
@Test
public void randomProtoMessage_messageFieldPopulated() {
ApkTargeting randomProto = ProtoFuzzer.randomProtoMessage(ApkTargeting.class);
assertThat(randomProto.getAbiTargeting()).isNotEqualToDefaultInstance();
}
use of com.android.bundle.Targeting.ApkTargeting in project bundletool by google.
the class LanguageResourcesSplitterTest method resourcesPinnedToMasterSplit_noSplitting_strings.
@Test
public void resourcesPinnedToMasterSplit_noSplitting_strings() throws Exception {
ResourceTable resourceTable = getStringResourceTable("welcome_label", ImmutableList.of(value("hello", locale("en")), value("bienvenue", locale("fr"))), "text2", ImmutableList.of(value("no worries", locale("en")), value("de rien", locale("fr"))));
BundleModule module = new BundleModuleBuilder("testModule").setResourceTable(resourceTable).setManifest(androidManifest("com.test.app")).build();
ModuleSplit baseSplit = ModuleSplit.forResources(module);
LanguageResourcesSplitter languageSplitter = new LanguageResourcesSplitter(resource -> resource.getResourceId().getFullResourceId() == 0x7f010001);
Collection<ModuleSplit> languageSplits = languageSplitter.split(baseSplit);
ModuleSplit masterSplit = languageSplits.stream().filter(split -> split.isMasterSplit()).collect(onlyElement());
assertThat(masterSplit.getResourceTable()).hasValue(getStringResourceTable("welcome_label", 0x01, ImmutableList.of(value("hello", locale("en")), value("bienvenue", locale("fr")))));
ImmutableList<ModuleSplit> configSplits = languageSplits.stream().filter(split -> !split.isMasterSplit()).collect(toImmutableList());
ImmutableMap<ApkTargeting, ModuleSplit> configSplitMap = Maps.uniqueIndex(configSplits, ModuleSplit::getApkTargeting);
assertThat(configSplitMap.keySet()).containsExactly(apkLanguageTargeting("en"), apkLanguageTargeting("fr"));
assertThat(configSplitMap.get(apkLanguageTargeting("en")).getResourceTable()).hasValue(getStringResourceTable("text2", 0x02, ImmutableList.of(value("no worries", locale("en")))));
assertThat(configSplitMap.get(apkLanguageTargeting("fr")).getResourceTable()).hasValue(getStringResourceTable("text2", 0x02, ImmutableList.of(value("de rien", locale("fr")))));
}
Aggregations