Search in sources :

Example 11 with LanguageTargeting

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");
}
Also used : TargetingUtils.alternativeLanguageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.alternativeLanguageTargeting) LanguageTargeting(com.android.bundle.Targeting.LanguageTargeting) TargetingUtils.apkLanguageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkLanguageTargeting) TargetingUtils.apkAlternativeLanguageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkAlternativeLanguageTargeting) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 12 with LanguageTargeting

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");
}
Also used : Arrays(java.util.Arrays) ApkTargeting(com.android.bundle.Targeting.ApkTargeting) BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) VariantKey(com.android.tools.build.bundletool.model.VariantKey) XmlProtoNode(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoNode) RunWith(org.junit.runner.RunWith) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) XmlProtoAttributeBuilder(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoAttributeBuilder) BASE_MODULE_NAME(com.android.tools.build.bundletool.model.BundleModuleName.BASE_MODULE_NAME) MoreCollectors.onlyElement(com.google.common.collect.MoreCollectors.onlyElement) TruthResourceTable.assertThat(com.android.tools.build.bundletool.testing.truth.resources.TruthResourceTable.assertThat) HashSet(java.util.HashSet) ProtoTruth.assertThat(com.google.common.truth.extensions.proto.ProtoTruth.assertThat) ImmutableList(com.google.common.collect.ImmutableList) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) Theories(org.junit.experimental.theories.Theories) TargetingUtils.languageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.languageTargeting) SYSTEM(com.android.tools.build.bundletool.model.ModuleSplit.SplitType.SYSTEM) ResourceTable(com.android.aapt.Resources.ResourceTable) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) Nullable(javax.annotation.Nullable) Before(org.junit.Before) XmlProtoElementBuilder(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoElementBuilder) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) LanguageTargeting(com.android.bundle.Targeting.LanguageTargeting) SplitType(com.android.tools.build.bundletool.model.ModuleSplit.SplitType) XmlNode(com.android.aapt.Resources.XmlNode) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ExtensionRegistry(com.google.protobuf.ExtensionRegistry) SPLIT(com.android.tools.build.bundletool.model.ModuleSplit.SplitType.SPLIT) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) Test(org.junit.Test)

Example 13 with LanguageTargeting

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));
}
Also used : LanguageTargeting(com.android.bundle.Targeting.LanguageTargeting) DeviceTierTargeting(com.android.bundle.Targeting.DeviceTierTargeting) HashMap(java.util.HashMap) AbiTargeting(com.android.bundle.Targeting.AbiTargeting) SdkVersionTargeting(com.android.bundle.Targeting.SdkVersionTargeting) TextureCompressionFormatTargeting(com.android.bundle.Targeting.TextureCompressionFormatTargeting) SizeConfiguration(com.android.tools.build.bundletool.model.SizeConfiguration) ScreenDensityTargeting(com.android.bundle.Targeting.ScreenDensityTargeting)

Example 14 with LanguageTargeting

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());
}
Also used : LanguageTargeting(com.android.bundle.Targeting.LanguageTargeting) Test(org.junit.Test)

Example 15 with LanguageTargeting

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);
}
Also used : LanguageTargeting(com.android.bundle.Targeting.LanguageTargeting) Test(org.junit.Test)

Aggregations

LanguageTargeting (com.android.bundle.Targeting.LanguageTargeting)17 Test (org.junit.Test)15 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)13 ApkTargeting (com.android.bundle.Targeting.ApkTargeting)12 VariantTargeting (com.android.bundle.Targeting.VariantTargeting)12 AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)12 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)12 TargetingUtils.languageTargeting (com.android.tools.build.bundletool.testing.TargetingUtils.languageTargeting)12 ImmutableList (com.google.common.collect.ImmutableList)12 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)12 ImmutableMap (com.google.common.collect.ImmutableMap)12 MoreCollectors.onlyElement (com.google.common.collect.MoreCollectors.onlyElement)12 Truth.assertThat (com.google.common.truth.Truth.assertThat)12 ProtoTruth.assertThat (com.google.common.truth.extensions.proto.ProtoTruth.assertThat)12 Before (org.junit.Before)12 Theories (org.junit.experimental.theories.Theories)12 RunWith (org.junit.runner.RunWith)12 ResourceTable (com.android.aapt.Resources.ResourceTable)7 XmlNode (com.android.aapt.Resources.XmlNode)7 TextureCompressionFormatTargeting (com.android.bundle.Targeting.TextureCompressionFormatTargeting)7