use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.
the class SystemApksGeneratorTest method shardByAbiAndDensity_multipleLanguageResourceAndDeviceSpecMissingLanguage_fallsBackToDefault.
@Test
public void shardByAbiAndDensity_multipleLanguageResourceAndDeviceSpecMissingLanguage_fallsBackToDefault() throws Exception {
BundleModule bundleModule = new BundleModuleBuilder("base").addFile("dex/classes.dex").addFile("lib/x86/libtest.so").addFile("root/license.dat").addFile("assets/languages#lang_es/image.jpg").addFile("assets/languages#lang_fr/image.jpg").addFile("assets/languages/image.jpg").setManifest(androidManifest("com.test.app")).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)))).setAssetsConfig(assets(targetedAssetsDirectory("assets/languages#lang_es", assetsDirectoryTargeting(languageTargeting("es"))), targetedAssetsDirectory("assets/languages#lang_fr", assetsDirectoryTargeting(languageTargeting("fr"))), targetedAssetsDirectory("assets/languages", assetsDirectoryTargeting(alternativeLanguageTargeting("es", "fr"))))).setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addStringResourceForMultipleLocales("text", ImmutableMap.of(/* default locale */
"", "hello", "es", "hola", "fr", "bonjour")).build()).build();
ImmutableList<ModuleSplit> shards = systemApksGenerator.generateSystemApks(/* modules= */
ImmutableList.of(bundleModule), /* modulesToFuse= */
ImmutableSet.of(BASE_MODULE_NAME), splitOptimizations(OptimizationDimension.ABI, OptimizationDimension.SCREEN_DENSITY, OptimizationDimension.LANGUAGE));
ModuleSplit fatShard = getSystemImageSplit(shards);
assertThat(fatShard.getApkTargeting()).isEqualTo(mergeApkTargeting(apkAbiTargeting(X86), apkAlternativeLanguageTargeting("es", "fr")));
assertThat(fatShard.getApkTargeting().getAbiTargeting()).isEqualTo(abiTargeting(X86));
assertThat(fatShard.getApkTargeting().getScreenDensityTargeting()).isEqualToDefaultInstance();
assertThat(fatShard.getVariantTargeting()).isEqualTo(mergeVariantTargeting(variantMinSdkTargeting(1), variantAbiTargeting(X86)));
assertThat(fatShard.getSplitType()).isEqualTo(SplitType.SYSTEM);
assertThat(fatShard.getResourceTable().get()).isEqualTo(new ResourceTableBuilder().addPackage("com.test.app").addStringResourceForMultipleLocales("text", ImmutableMap.of(/* default locale */
"", "hello")).build());
assertThat(extractPaths(fatShard.getEntries())).containsExactly("dex/classes.dex", "lib/x86/libtest.so", "root/license.dat", "assets/languages/image.jpg");
ImmutableMap<LanguageTargeting, ModuleSplit> splitLanguageTargetingMap = Maps.uniqueIndex(getAdditionalSplits(shards), split -> split.getApkTargeting().getLanguageTargeting());
assertThat(splitLanguageTargetingMap.keySet()).containsExactly(languageTargeting("es"), languageTargeting("fr"));
ModuleSplit esLangShard = splitLanguageTargetingMap.get(languageTargeting("es"));
assertThat(esLangShard.getApkTargeting()).isEqualTo(apkLanguageTargeting("es"));
assertThat(esLangShard.getSplitType()).isEqualTo(SplitType.SYSTEM);
assertThat(esLangShard.getResourceTable().get()).isEqualTo(new ResourceTableBuilder().addPackage("com.test.app").addStringResourceForMultipleLocales("text", ImmutableMap.of("es", "hola")).build());
assertThat(extractPaths(esLangShard.getEntries())).containsExactly("assets/languages#lang_es/image.jpg");
ModuleSplit frLangShard = splitLanguageTargetingMap.get(languageTargeting("fr"));
assertThat(frLangShard.getApkTargeting()).isEqualTo(apkLanguageTargeting("fr"));
assertThat(frLangShard.getSplitType()).isEqualTo(SplitType.SYSTEM);
assertThat(frLangShard.getResourceTable().get()).isEqualTo(new ResourceTableBuilder().addPackage("com.test.app").addStringResourceForMultipleLocales("text", ImmutableMap.of("fr", "bonjour")).build());
assertThat(extractPaths(frLangShard.getEntries())).containsExactly("assets/languages#lang_fr/image.jpg");
}
use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.
the class LocaleConfigXmlInjectorTest method process_noLanguageTargeting.
@Test
public void process_noLanguageTargeting() throws Exception {
ModuleSplit baseMasterSplit = createModuleSplit(new ResourceTableBuilder().addPackage("com.example.app.module").build(), BASE_MODULE_NAME.getName(), /* masterSplit= */
true, SPLIT, /* languageTargeting= */
null);
ModuleSplit otherSplit = createModuleSplit(new ResourceTableBuilder().addPackage("com.example.app.module").build(), BASE_MODULE_NAME.getName(), /* masterSplit= */
false, SPLIT, /* languageTargeting= */
null);
ModuleSplit processedBaseMasterSplit = localeConfigXmlInjector.process(VariantKey.create(baseMasterSplit), ImmutableList.of(baseMasterSplit, otherSplit)).stream().filter(split -> split.isMasterSplit() && split.isBaseModuleSplit()).collect(onlyElement());
assertThat(processedBaseMasterSplit.getAndroidManifest().hasLocaleConfig()).isFalse();
assertThat(processedBaseMasterSplit.getResourceTable().get()).doesNotContainResource("com.example.app.module:xml/locales_config");
}
use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.
the class ResourcesUtilsTest method lookupEntryByResourceId_negativeId.
@Test
public void lookupEntryByResourceId_negativeId() {
ResourceTable resourceTable = new ResourceTableBuilder().addPackage("com.test.app", 0x7F).addXmlResource("layout", "res/xml/not-the-layout-we-want.xml").addPackage("com.test.app.split", 0x80).addXmlResource("layout", "res/xml/layout.xml").addStringResource("hello", "res/string/hello.xml").addStringResource("world", "res/string/world.xml").build();
Optional<Entry> layoutResource = ResourcesUtils.lookupEntryByResourceId(resourceTable, 0x80010000);
assertThat(layoutResource).isPresent();
assertThat(extractFilePathValues(layoutResource.get())).containsExactly("res/xml/layout.xml");
Optional<Entry> helloResource = ResourcesUtils.lookupEntryByResourceId(resourceTable, 0x80020000);
assertThat(helloResource).isPresent();
assertThat(extractStringValues(helloResource.get())).containsExactly("res/string/hello.xml");
Optional<Entry> worldResource = ResourcesUtils.lookupEntryByResourceId(resourceTable, 0x80020001);
assertThat(worldResource).isPresent();
assertThat(extractStringValues(worldResource.get())).containsExactly("res/string/world.xml");
}
use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.
the class ScreenDensityResourcesSplitterTest method manifestMutatorToRequireSplits_registered_whenDensityResourcesPresent.
@Test
public void manifestMutatorToRequireSplits_registered_whenDensityResourcesPresent() 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(MDPI_VALUE, "res/drawable-ldpi/image.jpg", HDPI_VALUE, "res/drawable-dpi/image.jpg")).build()).setManifest(androidManifest("com.test.app")).build();
ImmutableCollection<ModuleSplit> densitySplits = splitter.split(ModuleSplit.forResources(testModule));
ImmutableList<ModuleSplit> configSplits = densitySplits.stream().filter(split -> !split.isMasterSplit()).collect(toImmutableList());
assertThat(configSplits).isNotEmpty();
for (ModuleSplit configSplit : configSplits) {
assertThat(compareManifestMutators(configSplit.getMasterManifestMutators(), withSplitsRequired(true))).isTrue();
}
}
use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.
the class ScreenDensityResourcesSplitterTest method lowestDensityConfigsPinnedToMaster_masterCoversRangeOfDensities.
@Test
public void lowestDensityConfigsPinnedToMaster_masterCoversRangeOfDensities() throws Exception {
BundleModule testModule = new BundleModuleBuilder("testModule").addFile("res/drawable-ldpi/image.jpg").addFile("res/drawable-xxxhdpi/image.jpg").addFile("res/drawable-ldpi/other.jpg").addFile("res/drawable-mdpi/other.jpg").addFile("res/drawable-tvdpi/other.jpg").addFile("res/drawable-xhdpi/other.jpg").addFile("res/drawable-xxhdpi/other.jpg").addFile("res/drawable-xxxhdpi/other.jpg").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("image", ImmutableMap.of(/* ldpi */
120, "res/drawable-ldpi/image.jpg", /* xxxhdpi */
640, "res/drawable-xxxhdpi/image.jpg")).addDrawableResourceForMultipleDensities("other", ImmutableMap.<Integer, String>builder().put(/* ldpi */
120, "res/drawable-ldpi/other.jpg").put(/* mdpi */
160, "res/drawable-mdpi/other.jpg").put(/* tvdpi */
213, "res/drawable-tvdpi/other.jpg").put(/* hdpi */
240, "res/drawable-hdpi/other.jpg").put(/* xhdpi */
320, "res/drawable-xhdpi/other.jpg").put(/* xxhdpi */
480, "res/drawable-xxhdpi/other.jpg").put(/* xxxhdpi */
640, "res/drawable-xxxhdpi/image.jpg").build()).build()).setManifest(androidManifest("com.test.app")).build();
// 0x7f010000 is the "drawable/image" resource.
Predicate<ResourceId> pinnedLowDensityResourcesPredicate = resourceId -> resourceId.getFullResourceId() == 0x7f010000;
ScreenDensityResourcesSplitter splitter = new ScreenDensityResourcesSplitter(BundleToolVersion.getCurrentVersion(), NO_RESOURCES_PINNED_TO_MASTER, pinnedLowDensityResourcesPredicate, /* pinLowestBucketOfStylesToMaster= */
false);
ImmutableCollection<ModuleSplit> densitySplits = splitter.split(ModuleSplit.forResources(testModule));
ImmutableList<ModuleSplit> configSplits = densitySplits.stream().filter(split -> !split.isMasterSplit()).collect(toImmutableList());
assertThat(configSplits).isNotEmpty();
for (ModuleSplit configSplit : configSplits) {
DensityAlias targetDensity = configSplit.getApkTargeting().getScreenDensityTargeting().getValue(0).getDensityAlias();
switch(targetDensity) {
case LDPI:
case MDPI:
// Devices <= MDPI are covered by the LDPI config.
assertThat(extractPaths(configSplit.getEntries())).doesNotContain("res/drawable-xxxhdpi/image.jpg");
break;
default:
// Devices > MDPI are covered by the XXXHDPI config.
assertThat(extractPaths(configSplit.getEntries())).contains("res/drawable-xxxhdpi/image.jpg");
}
}
}
Aggregations