use of com.android.bundle.Targeting.ApkTargeting in project bundletool by google.
the class TargetingUtilsTest method apkMultiAbiTargeting_byMultipleAbisAndAlternatives.
@Test
public void apkMultiAbiTargeting_byMultipleAbisAndAlternatives() {
ApkTargeting expectedTargeting = ApkTargeting.newBuilder().setMultiAbiTargeting(MULTI_ABI_WITH_ALTERNATIVES).build();
assertThat(TargetingUtils.apkMultiAbiTargeting(ImmutableSet.of(ImmutableSet.of(X86), ImmutableSet.of(ARMEABI_V7A, ARM64_V8A)), ImmutableSet.of(ImmutableSet.of(X86_64)))).ignoringRepeatedFieldOrder().isEqualTo(expectedTargeting);
}
use of com.android.bundle.Targeting.ApkTargeting in project bundletool by google.
the class LanguageResourcesSplitterTest method resourcesPinnedToMasterSplit_noSplitting_fileReferences.
@Test
public void resourcesPinnedToMasterSplit_noSplitting_fileReferences() throws Exception {
ResourceTable resourceTable = new ResourceTableBuilder().addPackage("com.test.app").addResource("drawable", "image", fileReference("res/drawable-en-hdpi/image.jpg", mergeConfigs(locale("en"), HDPI)), fileReference("res/drawable-fr-hdpi/image.jpg", mergeConfigs(locale("fr"), HDPI))).addResource("drawable", "image2", fileReference("res/drawable-en-hdpi/image2.jpg", mergeConfigs(locale("en"), HDPI)), fileReference("res/drawable-fr-hdpi/image2.jpg", mergeConfigs(locale("fr"), HDPI))).build();
BundleModule module = new BundleModuleBuilder("testModule").setResourceTable(resourceTable).setManifest(androidManifest("com.test.app")).addFile("res/drawable-en-hdpi/image.jpg").addFile("res/drawable-fr-hdpi/image.jpg").addFile("res/drawable-en-hdpi/image2.jpg").addFile("res/drawable-fr-hdpi/image2.jpg").build();
ModuleSplit baseSplit = ModuleSplit.forResources(module);
LanguageResourcesSplitter languageSplitter = new LanguageResourcesSplitter(resource -> resource.getResourceId().getFullResourceId() == 0x7f010000);
Collection<ModuleSplit> languageSplits = languageSplitter.split(baseSplit);
ModuleSplit masterSplit = languageSplits.stream().filter(split -> split.isMasterSplit()).collect(onlyElement());
assertThat(masterSplit.getResourceTable()).hasValue(new ResourceTableBuilder().addPackage("com.test.app").addResource("drawable", "image", fileReference("res/drawable-en-hdpi/image.jpg", mergeConfigs(locale("en"), HDPI)), fileReference("res/drawable-fr-hdpi/image.jpg", mergeConfigs(locale("fr"), HDPI))).build());
assertThat(extractPaths(masterSplit.getEntries())).containsExactly("res/drawable-en-hdpi/image.jpg", "res/drawable-fr-hdpi/image.jpg");
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"));
ModuleSplit enSplit = configSplitMap.get(apkLanguageTargeting("en"));
assertThat(enSplit.getResourceTable()).hasValue(ResourcesTableFactory.createResourceTable(/* entryId= */
0x01, "image2", fileReference("res/drawable-en-hdpi/image2.jpg", mergeConfigs(locale("en"), HDPI))));
assertThat(extractPaths(enSplit.getEntries())).containsExactly("res/drawable-en-hdpi/image2.jpg");
ModuleSplit frSplit = configSplitMap.get(apkLanguageTargeting("fr"));
assertThat(frSplit.getResourceTable()).hasValue(ResourcesTableFactory.createResourceTable(/* entryId= */
0x01, "image2", fileReference("res/drawable-fr-hdpi/image2.jpg", mergeConfigs(locale("fr"), HDPI))));
assertThat(extractPaths(frSplit.getEntries())).containsExactly("res/drawable-fr-hdpi/image2.jpg");
}
use of com.android.bundle.Targeting.ApkTargeting in project bundletool by google.
the class SplitApksGeneratorTest method multipleModules_multipleVariants_withTransparency.
@Test
public void multipleModules_multipleVariants_withTransparency() throws Exception {
TestComponent.useTestModule(this, TestModule.builder().withBundleMetadata(BUNDLE_METADATA_WITH_TRANSPARENCY).build());
ImmutableList<BundleModule> bundleModule = ImmutableList.of(new BundleModuleBuilder("base").addFile("assets/leftover.txt").addFile("lib/x86_64/libsome.so").setManifest(androidManifest("com.test.app")).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(AbiAlias.X86_64)))).build(), new BundleModuleBuilder("test").addFile("assets/test.txt").setManifest(androidManifest("com.test.app")).build());
ImmutableList<ModuleSplit> moduleSplits = splitApksGenerator.generateSplits(bundleModule, ApkGenerationConfiguration.builder().setOptimizationDimensions(ImmutableSet.of(OptimizationDimension.ABI)).build());
ApkTargeting minSdkLTargeting = apkMinSdkTargeting(/* minSdkVersion= */
ANDROID_L_API_VERSION);
ApkTargeting minSdkLWithAbiTargeting = mergeApkTargeting(apkAbiTargeting(AbiAlias.X86_64), minSdkLTargeting);
// 1 main and 1 ABI split for base module + test module.
assertThat(moduleSplits).hasSize(3);
assertThat(moduleSplits.stream().map(ModuleSplit::getApkTargeting).collect(toImmutableSet())).containsExactly(minSdkLTargeting, minSdkLWithAbiTargeting);
ModuleSplit mainSplitOfBaseModule = getModuleSplit(moduleSplits, minSdkLTargeting, /* moduleName= */
"base");
assertThat(extractPaths(mainSplitOfBaseModule.getEntries())).containsExactly("assets/leftover.txt", "META-INF/code_transparency_signed.jwt");
ModuleSplit abiSplitOfBaseModule = getModuleSplit(moduleSplits, minSdkLWithAbiTargeting, /* moduleName= */
"base");
assertThat(extractPaths(abiSplitOfBaseModule.getEntries())).containsExactly("lib/x86_64/libsome.so");
ModuleSplit testModule = getModuleSplit(moduleSplits, minSdkLTargeting, /* moduleName= */
"test");
assertThat(extractPaths(testModule.getEntries())).containsExactly("assets/test.txt");
}
use of com.android.bundle.Targeting.ApkTargeting 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.bundle.Targeting.ApkTargeting in project bundletool by google.
the class ModuleSplitterTest method nativeSplits_areGenerated.
@Test
public void nativeSplits_areGenerated() throws Exception {
NativeLibraries nativeConfig = nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting("x86")));
BundleModule testModule = new BundleModuleBuilder("testModule").setManifest(androidManifest("com.test.app")).setNativeConfig(nativeConfig).addFile("lib/x86/liba.so").build();
ImmutableList<ModuleSplit> splits = createAbiAndDensitySplitter(testModule).splitModule();
assertThat(splits.stream().map(ModuleSplit::getSplitType).distinct().collect(toImmutableSet())).containsExactly(SplitType.SPLIT);
assertThat(splits.stream().map(ModuleSplit::getVariantTargeting).distinct().collect(toImmutableSet())).containsExactly(lPlusVariantTargeting());
assertThat(splits).hasSize(2);
boolean hasMasterSplit = false;
boolean hasX86Split = false;
ApkTargeting x86SplitTargeting = mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkAbiTargeting(AbiAlias.X86));
for (ModuleSplit split : splits) {
if (split.getApkTargeting().equals(DEFAULT_MASTER_SPLIT_SDK_TARGETING)) {
assertThat(split.isMasterSplit()).isTrue();
hasMasterSplit = true;
} else if (split.getApkTargeting().equals(x86SplitTargeting)) {
assertThat(split.isMasterSplit()).isFalse();
hasX86Split = true;
} else {
fail(String.format("Unexpected split targeting: %s", split.getApkTargeting()));
}
}
assertThat(hasMasterSplit).isTrue();
assertThat(hasX86Split).isTrue();
}
Aggregations