use of com.android.bundle.Targeting.ApkTargeting 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());
}
use of com.android.bundle.Targeting.ApkTargeting in project bundletool by google.
the class AbiApexImagesSplitterTest method splittingBySingleAbi_twoImageFilesWithBuildInfo.
@Test
public void splittingBySingleAbi_twoImageFilesWithBuildInfo() throws Exception {
ApexImages apexConfig = apexImages(targetedApexImageWithBuildInfo("apex/x86.img", "apex/x86.build_info.pb", apexImageTargeting("x86")), targetedApexImageWithBuildInfo("apex/x86_64.img", "apex/x86_64.build_info.pb", apexImageTargeting("x86_64")));
BundleModule bundleModule = new BundleModuleBuilder("testModule").addFile("apex/x86.img").addFile("apex/x86.build_info.pb").addFile("apex/x86_64.img").addFile("apex/x86_64.build_info.pb").setApexConfig(apexConfig).setManifest(androidManifest("com.test.app")).build();
AbiApexImagesSplitter abiApexImagesSplitter = new AbiApexImagesSplitter();
ImmutableCollection<ModuleSplit> splits = abiApexImagesSplitter.split(ModuleSplit.forApex(bundleModule));
assertThat(splits).hasSize(2);
ApkTargeting x86Targeting = apkMultiAbiTargeting(X86, ImmutableSet.of(X86_64));
ApkTargeting x64Targeting = apkMultiAbiTargeting(X86_64, ImmutableSet.of(X86));
ImmutableMap<ApkTargeting, ModuleSplit> splitsByTargeting = Maps.uniqueIndex(splits, ModuleSplit::getApkTargeting);
assertThat(splitsByTargeting.keySet()).containsExactly(x86Targeting, x64Targeting);
assertThat(extractPaths(splitsByTargeting.get(x86Targeting).getEntries())).containsExactly("apex/x86.img", "apex/x86.build_info.pb");
assertThat(extractPaths(splitsByTargeting.get(x64Targeting).getEntries())).containsExactly("apex/x86_64.img", "apex/x86_64.build_info.pb");
}
use of com.android.bundle.Targeting.ApkTargeting in project bundletool by google.
the class LanguageResourcesSplitterTest method languageResources_doesntSplitIfAlreadyTargeted.
@Test
public void languageResources_doesntSplitIfAlreadyTargeted() throws Exception {
ResourceTable resourceTable = getDrawableResourceTable(mergeConfigs(HDPI, locale("de")), "res/drawable-de-hdpi/welcome.png", mergeConfigs(MDPI, locale("fr")), "res/drawable-fr-mdpi/welcome.png", HDPI, "res/drawable-hdpi/welcome.png");
BundleModule module = new BundleModuleBuilder("testModule").setResourceTable(resourceTable).setManifest(androidManifest("com.test.app")).build();
ApkTargeting initialTargeting = apkDensityTargeting(DensityAlias.HDPI);
ModuleSplit densitySplit = ModuleSplit.forResources(module).toBuilder().setApkTargeting(initialTargeting).setMasterSplit(false).build();
Collection<ModuleSplit> languageSplits = languageSplitter.split(densitySplit);
assertThat(languageSplits).hasSize(1);
ModuleSplit languageSplit = languageSplits.iterator().next();
assertThat(languageSplit).isEqualTo(densitySplit);
}
use of com.android.bundle.Targeting.ApkTargeting in project bundletool by google.
the class LanguageResourcesSplitterTest method languageResources_addsToTargeting.
@Ignore("Re-enable after we can generate multi-dimensional splits.")
@Test
public void languageResources_addsToTargeting() throws Exception {
ResourceTable resourceTable = getDrawableResourceTable(mergeConfigs(HDPI, locale("de")), "res/drawable-de-hdpi/welcome.png", mergeConfigs(MDPI, locale("fr")), "res/drawable-fr-mdpi/welcome.png", HDPI, "res/drawable-hdpi/welcome.png");
BundleModule module = new BundleModuleBuilder("testModule").setResourceTable(resourceTable).setManifest(androidManifest("com.test.app")).build();
ApkTargeting initialTargeting = apkDensityTargeting(DensityAlias.HDPI);
ModuleSplit densitySplit = ModuleSplit.forResources(module).toBuilder().setApkTargeting(initialTargeting).setMasterSplit(false).build();
Collection<ModuleSplit> languageSplits = languageSplitter.split(densitySplit);
assertThat(languageSplits).hasSize(3);
assertThat(languageSplits.stream().map(ModuleSplit::getSplitType).distinct().collect(toImmutableSet())).containsExactly(SplitType.SPLIT);
boolean hasDeHdpiSplit = false;
boolean hasFrHdpiSplit = false;
boolean hasHdpiSplit = false;
for (ModuleSplit split : languageSplits) {
if (split.getApkTargeting().equals(initialTargeting)) {
hasHdpiSplit = true;
assertThat(split.getResourceTable().get()).isEqualTo(getDrawableResourceTable(HDPI, "res/drawable-hdpi/welcome.png"));
} else if (split.getApkTargeting().equals(mergeApkTargeting(apkLanguageTargeting("de"), initialTargeting))) {
hasDeHdpiSplit = true;
assertThat(split.getResourceTable().get()).isEqualTo(getDrawableResourceTable(mergeConfigs(HDPI, locale("de")), "res/drawable-de-hdpi/welcome.png"));
} else if (split.getApkTargeting().equals(mergeApkTargeting(apkLanguageTargeting("fr"), initialTargeting))) {
hasFrHdpiSplit = true;
assertThat(split.getResourceTable().get()).isEqualTo(getDrawableResourceTable(mergeConfigs(MDPI, locale("fr")), "res/drawable-fr-mdpi/welcome.png"));
} else {
fail(String.format("Unexpected targeting: %s", split.getApkTargeting()));
}
}
assertThat(hasHdpiSplit).isTrue();
assertThat(hasDeHdpiSplit).isTrue();
assertThat(hasFrHdpiSplit).isTrue();
}
use of com.android.bundle.Targeting.ApkTargeting in project bundletool by google.
the class MergingUtilsTest method mergeShardTargetings_differentTextureCompressionFormats_ok.
@Test
public void mergeShardTargetings_differentTextureCompressionFormats_ok() {
ApkTargeting targeting1 = apkTextureTargeting(textureCompressionTargeting(S3TC, ImmutableSet.of(ETC1_RGB8)));
ApkTargeting targeting2 = apkTextureTargeting(textureCompressionTargeting(S3TC, ImmutableSet.of(ATC)));
assertThat(MergingUtils.mergeShardTargetings(targeting1, targeting2)).isEqualTo(apkTextureTargeting(textureCompressionTargeting(S3TC, ImmutableSet.of(ETC1_RGB8, ATC))));
}
Aggregations