use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.
the class ShardedApksFacadeTest method singleModule_withNativeLibsAndLanguagesWithDeviceSpec.
@Test
public void singleModule_withNativeLibsAndLanguagesWithDeviceSpec() throws Exception {
TestComponent.useTestModule(this, TestModule.builder().withDeviceSpec(mergeSpecs(sdkVersion(28), abis("x86"), density(DensityAlias.MDPI), locales("es"))).build());
ImmutableList<BundleModule> bundleModule = ImmutableList.of(new BundleModuleBuilder("base").addFile("lib/x86/libsome.so").addFile("lib/x86_64/libsome.so").addFile("assets/languages#lang_es/image.jpg").addFile("assets/languages#lang_fr/image.jpg").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(AbiAlias.X86_64)))).setAssetsConfig(assets(targetedAssetsDirectory("assets/languages#lang_es", assetsDirectoryTargeting(languageTargeting("es"))), targetedAssetsDirectory("assets/languages#lang_fr", assetsDirectoryTargeting(languageTargeting("fr"))))).setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addStringResourceForMultipleLocales("text", ImmutableMap.of(/* default locale */
"", "hello", "es", "hola", "fr", "bonjour")).build()).setManifest(androidManifest("com.test.app")).build());
ImmutableList<ModuleSplit> moduleSplits = shardedApksFacade.generateSystemSplits(/* modules= */
bundleModule, /* modulesToFuse= */
ImmutableSet.of(BASE_MODULE_NAME), DEFAULT_APK_OPTIMIZATIONS);
// fused, es split
assertThat(moduleSplits).hasSize(2);
ImmutableMap<Boolean, ModuleSplit> splitByMasterSplitTypeMap = Maps.uniqueIndex(moduleSplits, ModuleSplit::isMasterSplit);
ModuleSplit fusedSplit = splitByMasterSplitTypeMap.get(true);
assertThat(fusedSplit.getApkTargeting()).isEqualTo(mergeApkTargeting(apkAbiTargeting(X86, ImmutableSet.of(X86_64)), apkLanguageTargeting("es")));
assertThat(fusedSplit.getSplitType()).isEqualTo(SplitType.SYSTEM);
assertThat(fusedSplit.isMasterSplit()).isTrue();
// fr strings missing from resource table.
assertThat(fusedSplit.getResourceTable().get()).isEqualTo(new ResourceTableBuilder().addPackage("com.test.app").addStringResourceForMultipleLocales("text", ImmutableMap.of(/* default locale */
"", "hello", "es", "hola")).build());
assertThat(extractPaths(fusedSplit.getEntries())).containsExactly("lib/x86/libsome.so", "assets/languages#lang_es/image.jpg");
assertThat(fusedSplit.getAndroidManifest().getSplitId()).isEmpty();
ModuleSplit frLangSplit = splitByMasterSplitTypeMap.get(false);
assertThat(frLangSplit.getApkTargeting()).isEqualTo(apkLanguageTargeting("fr"));
assertThat(frLangSplit.getVariantTargeting()).isEqualTo(fusedSplit.getVariantTargeting());
assertThat(frLangSplit.getSplitType()).isEqualTo(SplitType.SYSTEM);
assertThat(frLangSplit.isMasterSplit()).isFalse();
assertThat(frLangSplit.getResourceTable().get()).isEqualTo(new ResourceTableBuilder().addPackage("com.test.app").addStringResourceForMultipleLocales("text", ImmutableMap.of("fr", "bonjour")).build());
assertThat(extractPaths(frLangSplit.getEntries())).containsExactly("assets/languages#lang_fr/image.jpg");
assertThat(frLangSplit.getAndroidManifest().getSplitId()).hasValue("config.fr");
}
use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.
the class ShardedApksFacadeTest method singleModule_withNativeLibsAndDensity_strip64bitNativeLibs.
@Test
@Theory
public void singleModule_withNativeLibsAndDensity_strip64bitNativeLibs(@FromDataPoints("standaloneSplitTypes") SplitType standaloneSplitType) throws Exception {
Optimizations optimizations = Optimizations.newBuilder().setStandaloneConfig(StandaloneConfig.newBuilder().setStrip64BitLibraries(true)).build();
TestComponent.useTestModule(this, standaloneSplitType.equals(SplitType.SYSTEM) ? TestModule.builder().withDeviceSpec(DEVICE_SPEC).withBundleConfig(BundleConfig.newBuilder().setOptimizations(optimizations)).build() : TestModule.builder().withBundleConfig(BundleConfig.newBuilder().setOptimizations(optimizations)).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;
if (standaloneSplitType.equals(SplitType.SYSTEM)) {
moduleSplits = shardedApksFacade.generateSystemSplits(bundleModule, ImmutableSet.of(BASE_MODULE_NAME), DEFAULT_APK_OPTIMIZATIONS);
// x86, mdpi split
assertThat(moduleSplits).hasSize(1);
} else {
moduleSplits = shardedApksFacade.generateSplits(bundleModule, DEFAULT_APK_OPTIMIZATIONS);
// 7 (density), 1 (abi) split
assertThat(moduleSplits).hasSize(7);
}
// Verify that the only ABI is x86.
ImmutableSet<Abi> abiTargetings = moduleSplits.stream().map(ModuleSplit::getApkTargeting).map(ApkTargeting::getAbiTargeting).map(AbiTargeting::getValueList).flatMap(List::stream).collect(toImmutableSet());
assertThat(abiTargetings).containsExactly(toAbi(X86));
// And ABI has no alternatives.
ImmutableSet<Abi> abiAlternatives = moduleSplits.stream().map(ModuleSplit::getApkTargeting).map(ApkTargeting::getAbiTargeting).map(AbiTargeting::getAlternativesList).flatMap(List::stream).collect(toImmutableSet());
assertThat(abiAlternatives).isEmpty();
assertThat(moduleSplits.stream().map(ModuleSplit::getSplitType).collect(toImmutableSet())).containsExactly(standaloneSplitType);
}
use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.
the class StandaloneApksGeneratorTest method shardByNoDimension_producesOneApk.
@Test
public void shardByNoDimension_producesOneApk() throws Exception {
BundleModule bundleModule = new BundleModuleBuilder("base").addFile("assets/file.txt").addFile("dex/classes.dex").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/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), NO_DIMENSIONS);
assertThat(shards).hasSize(1);
ModuleSplit fatShard = shards.get(0);
assertThat(fatShard.getApkTargeting()).isEqualToDefaultInstance();
assertThat(fatShard.getVariantTargeting()).isEqualTo(VARIANT_TARGETING_WITH_SDK_1);
assertThat(fatShard.getSplitType()).isEqualTo(SplitType.STANDALONE);
assertThat(extractPaths(fatShard.getEntries())).containsExactly("assets/file.txt", "dex/classes.dex", "lib/x86/libtest.so", "lib/x86_64/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 SplitsXmlInjectorTest method process_archiveSplitTypes.
@Test
public void process_archiveSplitTypes() throws Exception {
ModuleSplit archived = createModuleSplit(BASE_MODULE_NAME.getName(), /* splitId= */
"", /* masterSplit= */
true, SplitType.ARCHIVE, /* languageTargeting= */
null);
ResourceTable archivedResourceTable = new ResourceTableBuilder().addPackage("com.example.app").addStringResourceForMultipleLocales("title", ImmutableMap.of("ru-RU", "title ru-RU", "fr", "title fr")).build();
archived = archived.toBuilder().setResourceTable(archivedResourceTable).build();
GeneratedApks generatedApks = GeneratedApks.fromModuleSplits(ImmutableList.of(archived));
ModuleSplit processedArchivedApk = xmlInjectorProcess(generatedApks).stream().collect(onlyElement());
assertThat(processedArchivedApk.getAndroidManifest().getMetadataResourceId("com.android.vending.splits")).isEmpty();
}
use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.
the class SplitsXmlInjectorTest method process_noLanguageTargeting.
@Test
public void process_noLanguageTargeting() throws Exception {
ResourceTable baseResourceTable = new ResourceTableBuilder().addPackage("com.example.app").addStringResourceForMultipleLocales("title", ImmutableMap.of("ru", "title ru-RU", "fr", "title fr", "es", "title es")).build();
ModuleSplit baseModule = createModuleSplit(BASE_MODULE_NAME.getName(), /* splitId= */
"", /* masterSplit= */
true, SPLIT, /* languageTargeting= */
null).toBuilder().setResourceTable(baseResourceTable).build();
ResourceTable featureResourceTable = new ResourceTableBuilder().addPackage("com.example.app.module").addStringResourceForMultipleLocales("module_str", ImmutableMap.of("ru", "module ru-RU")).build();
ModuleSplit featureModule = createModuleSplit("module", /* splitId= */
"module", /* masterSplit= */
true, SPLIT, /* languageTargeting= */
null).toBuilder().setResourceTable(featureResourceTable).build();
GeneratedApks generatedApks = GeneratedApks.fromModuleSplits(ImmutableList.of(baseModule, featureModule));
ModuleSplit processedBaseMasterSplit = xmlInjectorProcess(generatedApks).stream().filter(module -> module.isMasterSplit() && module.isBaseModuleSplit()).collect(onlyElement());
assertThat(processedBaseMasterSplit.getResourceTable().get()).containsResource("com.example.app:xml/splits0").withFileReference("res/xml/splits0.xml");
XmlNode expectedSplitsProtoXml = new SplitsProtoXmlBuilder().addLanguageMapping(BundleModuleName.create("module"), "ru", "module").addLanguageMapping(BASE_MODULE_NAME, "ru", "").addLanguageMapping(BASE_MODULE_NAME, "fr", "").addLanguageMapping(BASE_MODULE_NAME, "es", "").build();
Optional<ModuleEntry> splitsXml = processedBaseMasterSplit.findEntry("res/xml/splits0.xml");
assertThat(splitsXml).isPresent();
assertThat(XmlNode.parseFrom(splitsXml.get().getContent().read(), ExtensionRegistry.getEmptyRegistry())).ignoringRepeatedFieldOrder().isEqualTo(expectedSplitsProtoXml);
}
Aggregations