use of com.android.bundle.Targeting.LanguageTargeting 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.bundle.Targeting.LanguageTargeting 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.bundle.Targeting.LanguageTargeting in project bundletool by google.
the class AbstractSizeAggregator method getSizesPerConfiguration.
protected ConfigurationSizes getSizesPerConfiguration(ImmutableSet<SdkVersionTargeting> sdkTargetingOptions, ImmutableSet<AbiTargeting> abiTargetingOptions, ImmutableSet<LanguageTargeting> languageTargetingOptions, ImmutableSet<ScreenDensityTargeting> screenDensityTargetingOptions, ImmutableSet<TextureCompressionFormatTargeting> textureCompressionFormatTargetingOptions, ImmutableSet<DeviceTierTargeting> deviceTierTargetingOptions) {
Map<SizeConfiguration, Long> minSizeByConfiguration = new HashMap<>();
Map<SizeConfiguration, Long> maxSizeByConfiguration = new HashMap<>();
for (SdkVersionTargeting sdkVersionTargeting : sdkTargetingOptions) {
for (AbiTargeting abiTargeting : abiTargetingOptions) {
for (ScreenDensityTargeting screenDensityTargeting : screenDensityTargetingOptions) {
for (LanguageTargeting languageTargeting : languageTargetingOptions) {
for (TextureCompressionFormatTargeting textureCompressionFormatTargeting : textureCompressionFormatTargetingOptions) {
for (DeviceTierTargeting deviceTierTargeting : deviceTierTargetingOptions) {
SizeConfiguration configuration = mergeWithDeviceSpec(getSizeConfiguration(sdkVersionTargeting, abiTargeting, screenDensityTargeting, languageTargeting, textureCompressionFormatTargeting, deviceTierTargeting), getSizeRequest.getDeviceSpec());
long compressedSize = getCompressedSize(getMatchingApks(sdkVersionTargeting, abiTargeting, screenDensityTargeting, languageTargeting, textureCompressionFormatTargeting, deviceTierTargeting));
minSizeByConfiguration.merge(configuration, compressedSize, Math::min);
maxSizeByConfiguration.merge(configuration, compressedSize, Math::max);
}
}
}
}
}
}
return ConfigurationSizes.create(/* minSizeConfigurationMap= */
ImmutableMap.copyOf(minSizeByConfiguration), /* maxSizeConfigurationMap= */
ImmutableMap.copyOf(maxSizeByConfiguration));
}
use of com.android.bundle.Targeting.LanguageTargeting in project bundletool by google.
the class ProtoFuzzerTest method shuffleRepeatedFields.
@Test
public void shuffleRepeatedFields() {
LanguageTargeting original = LanguageTargeting.newBuilder().addAllValue(LETTERS_A_TO_Z).addAllAlternatives(LETTERS_A_TO_Z).build();
LanguageTargeting shuffled = ProtoFuzzer.shuffleRepeatedFields(original);
// Values preserved.
assertThat(original.getValueList()).containsExactlyElementsIn(shuffled.getValueList());
assertThat(original.getAlternativesList()).containsExactlyElementsIn(shuffled.getAlternativesList());
// Order changed
assertThat(LETTERS_A_TO_Z).isNotEqualTo(shuffled.getValueList());
assertThat(LETTERS_A_TO_Z).isNotEqualTo(shuffled.getAlternativesList());
}
use of com.android.bundle.Targeting.LanguageTargeting in project bundletool by google.
the class ProtoFuzzerTest method randomProtoMessage_repeatedNonMessageFieldPopulated.
@Test
public void randomProtoMessage_repeatedNonMessageFieldPopulated() {
LanguageTargeting randomProto = ProtoFuzzer.randomProtoMessage(LanguageTargeting.class);
// At least some values populated.
assertThat(randomProto).isNotEqualTo(LanguageTargeting.getDefaultInstance());
// Not all random values are the same.
assertThat(ImmutableSet.copyOf(randomProto.getValueList()).size()).isGreaterThan(1);
assertThat(ImmutableSet.copyOf(randomProto.getAlternativesList()).size()).isGreaterThan(1);
}
Aggregations