Search in sources :

Example 6 with ApkTargeting

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());
}
Also used : ApkTargeting(com.android.bundle.Targeting.ApkTargeting) TargetingUtils.mergeApkTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeApkTargeting) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) ResourceTable(com.android.aapt.Resources.ResourceTable) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 7 with ApkTargeting

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");
}
Also used : ApexImages(com.android.bundle.Files.ApexImages) ApkTargeting(com.android.bundle.Targeting.ApkTargeting) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 8 with ApkTargeting

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);
}
Also used : ApkTargeting(com.android.bundle.Targeting.ApkTargeting) TargetingUtils.mergeApkTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeApkTargeting) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ResourceTable(com.android.aapt.Resources.ResourceTable) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 9 with ApkTargeting

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();
}
Also used : ApkTargeting(com.android.bundle.Targeting.ApkTargeting) TargetingUtils.mergeApkTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeApkTargeting) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ResourceTable(com.android.aapt.Resources.ResourceTable) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with ApkTargeting

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))));
}
Also used : ApkTargeting(com.android.bundle.Targeting.ApkTargeting) TargetingUtils.mergeApkTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeApkTargeting) Test(org.junit.Test)

Aggregations

ApkTargeting (com.android.bundle.Targeting.ApkTargeting)49 Test (org.junit.Test)44 TargetingUtils.mergeApkTargeting (com.android.tools.build.bundletool.testing.TargetingUtils.mergeApkTargeting)28 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)22 BundleModule (com.android.tools.build.bundletool.model.BundleModule)18 BundleModuleBuilder (com.android.tools.build.bundletool.testing.BundleModuleBuilder)18 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)10 ResourceTable (com.android.aapt.Resources.ResourceTable)8 DensityAlias (com.android.bundle.Targeting.ScreenDensity.DensityAlias)7 ImmutableList (com.google.common.collect.ImmutableList)7 ImmutableSet (com.google.common.collect.ImmutableSet)7 ApexImages (com.android.bundle.Files.ApexImages)6 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)6 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)6 Configuration (com.android.aapt.ConfigurationOuterClass.Configuration)5 ZipPath (com.android.tools.build.bundletool.model.ZipPath)5 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)5 MDPI (com.android.tools.build.bundletool.testing.ResourcesTableFactory.MDPI)5 USER_PACKAGE_OFFSET (com.android.tools.build.bundletool.testing.ResourcesTableFactory.USER_PACKAGE_OFFSET)5 ImmutableMap (com.google.common.collect.ImmutableMap)5