Search in sources :

Example 96 with BundleModule

use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.

the class ScreenDensityResourcesSplitterTest method densityBucket_neighbouringResources_edgeCase.

/**
 * An edge case where xxxhdpi split capturing devices from 527dpi and above should capture 512dpi
 * resources and above.
 *
 * <p>The 512dpi threshold depends on what other dpi values are available. Here, it's driven by
 * the presence of 560dpi config value. A 527dpi device prefers 512dpi over 560dpi.
 *
 * <p>The 512dpi resource should also be present in the xxhdpi split. It targets all devices up to
 * 526dpi.
 */
@Test
public void densityBucket_neighbouringResources_edgeCase() throws Exception {
    ResourceTable table = resourceTable(pkg(USER_PACKAGE_OFFSET, "com.test.app", type(0x01, "drawable", entry(0x01, "image", fileReference("res/drawable-mdpi/image.png", MDPI), fileReference("res/drawable-512dpi/image.png", forDpi(512)), fileReference("res/drawable-560dpi/image.png", _560DPI), fileReference("res/drawable-xxxhdpi/image.png", XXXHDPI)))));
    BundleModule module = new BundleModuleBuilder("base").addFile("res/drawable-mdpi/image.png").addFile("res/drawable-512dpi/image.png").addFile("res/drawable-560dpi/image.png").addFile("res/drawable-xxxhdpi/image.png").setResourceTable(table).setManifest(androidManifest("com.test.app")).build();
    ScreenDensityResourcesSplitter splitter = new ScreenDensityResourcesSplitter(ImmutableSet.of(DensityAlias.XXHDPI, DensityAlias.XXXHDPI), BundleToolVersion.getCurrentVersion(), NO_RESOURCES_PINNED_TO_MASTER, NO_LOW_DENSITY_CONFIG_PINNED_TO_MASTER, /* pinLowestBucketOfStylesToMaster =*/
    false);
    ImmutableCollection<ModuleSplit> densitySplits = splitter.split(ModuleSplit.forResources(module));
    ModuleSplit xxxhdpiSplit = findModuleSplitWithScreenDensityTargeting(densitySplits, ScreenDensity.newBuilder().setDensityAlias(DensityAlias.XXXHDPI).build());
    assertThat(xxxhdpiSplit.getResourceTable()).isPresent();
    ResourceTable xxxHdpiResourceTable = xxxhdpiSplit.getResourceTable().get();
    assertThat(xxxHdpiResourceTable).containsResource("com.test.app:drawable/image").withConfigSize(3).withDensity(XXXHDPI_VALUE).withDensity(560).withDensity(512);
    ModuleSplit xxhdpiSplit = findModuleSplitWithScreenDensityTargeting(densitySplits, ScreenDensity.newBuilder().setDensityAlias(DensityAlias.XXHDPI).build());
    Truth8.assertThat(xxhdpiSplit.getResourceTable()).isPresent();
    ResourceTable xxHdpiResourceTable = xxhdpiSplit.getResourceTable().get();
    assertThat(xxHdpiResourceTable).containsResource("com.test.app:drawable/image").withConfigSize(2).withDensity(MDPI_VALUE).withDensity(512);
}
Also used : 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 97 with BundleModule

use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.

the class ScreenDensityResourcesSplitterTest method preservesSourcePool.

@Test
public void preservesSourcePool() throws Exception {
    StringPool sourcePool = StringPool.newBuilder().setData(ByteString.copyFrom(new byte[] { 'x' })).build();
    ResourceTable table = new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("image", ImmutableMap.of(MDPI_VALUE, "res/drawable-mdpi/image.jpg")).build().toBuilder().setSourcePool(sourcePool).build();
    BundleModule testModule = new BundleModuleBuilder("testModule").addFile("res/drawable-mdpi/test.jpg").setResourceTable(table).setManifest(androidManifest("com.test.app")).build();
    ImmutableCollection<ModuleSplit> densitySplits = splitter.split(ModuleSplit.forResources(testModule));
    assertThat(densitySplits).hasSize(DEFAULT_DENSITY_BUCKETS.size() + 1);
    for (ModuleSplit densitySplit : densitySplits) {
        assertThat(densitySplit.getResourceTable()).isPresent();
        assertThat(densitySplit.getResourceTable().get().getSourcePool()).isEqualTo(sourcePool);
    }
}
Also used : StringPool(com.android.aapt.Resources.StringPool) 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 98 with BundleModule

use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.

the class StandaloneApksGeneratorTest method shardByAbi_havingSingleAbi_producesOneApk.

@Test
public void shardByAbi_havingSingleAbi_producesOneApk() throws Exception {
    BundleModule bundleModule = new BundleModuleBuilder("base").addFile("assets/file.txt").addFile("dex/classes.dex").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_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), standaloneApkOptimizations(OptimizationDimension.ABI));
    assertThat(shards).hasSize(1);
    ModuleSplit fatShard = shards.get(0);
    assertThat(fatShard.getApkTargeting()).isEqualTo(apkAbiTargeting(AbiAlias.X86_64));
    assertThat(fatShard.getVariantTargeting()).isEqualTo(mergeVariantTargeting(variantAbiTargeting(X86_64), VARIANT_TARGETING_WITH_SDK_1));
    assertThat(fatShard.getSplitType()).isEqualTo(SplitType.STANDALONE);
    assertThat(extractPaths(fatShard.getEntries())).containsExactly("assets/file.txt", "dex/classes.dex", "lib/x86_64/libtest.so", "res/drawable/image.jpg", "res/drawable-mdpi/image.jpg", "root/license.dat");
}
Also used : 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 99 with BundleModule

use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.

the class StandaloneApksGeneratorTest method shardByAbiAndDensity_havingOneAbiAndSomeDensityResource_produceManyApks_transparency.

@Test
public void shardByAbiAndDensity_havingOneAbiAndSomeDensityResource_produceManyApks_transparency() throws Exception {
    TestComponent.useTestModule(this, TestModule.builder().withBundleConfig(bundleConfigNodexmergestrategy).withBundleMetadata(BUNDLE_METADATA_WITH_TRANSPARENCY).build());
    BundleModule bundleModule = new BundleModuleBuilder("base").addFile("assets/file.txt").addFile("dex/classes.dex").addFile("lib/x86/libtest.so").addFile("res/drawable-ldpi/image.jpg").addFile("res/drawable-hdpi/image.jpg").addFile("root/license.dat").setManifest(androidManifest("com.test.app")).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)))).setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("image", ImmutableMap.of(LDPI_VALUE, "res/drawable-ldpi/image.jpg", HDPI_VALUE, "res/drawable-hdpi/image.jpg")).build()).build();
    ImmutableList<ModuleSplit> shards = standaloneApksGenerator.generateStandaloneApks(ImmutableList.of(bundleModule), standaloneApkOptimizations(OptimizationDimension.ABI, OptimizationDimension.SCREEN_DENSITY));
    // 7 shards: {x86} x {LDPI, MDPI, ..., XXXHDPI}.
    assertThat(shards).hasSize(7);
    assertThat(shards.stream().map(ModuleSplit::getSplitType).distinct().collect(toImmutableSet())).containsExactly(SplitType.STANDALONE);
    for (ModuleSplit shard : shards) {
        assertThat(extractPaths(shard.getEntries())).containsAtLeast("assets/file.txt", "dex/classes.dex", "lib/x86/libtest.so", "root/license.dat", "META-INF/code_transparency_signed.jwt");
    }
}
Also used : 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 100 with BundleModule

use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.

the class StandaloneApksGeneratorTest method manyModulesShardByNoDimension_producesFatApk.

@Test
public void manyModulesShardByNoDimension_producesFatApk() throws Exception {
    BundleModule baseModule = new BundleModuleBuilder("base").addFile("lib/x86_64/libtest1.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)))).addFile("res/drawable-ldpi/image1.jpg").setResourceTable(resourceTable(pkg(USER_PACKAGE_OFFSET, "com.test.app", type(0x01, "drawable", entry(0x01, "image1", fileReference("res/drawable-ldpi/image1.jpg", LDPI)))))).setManifest(androidManifest("com.test.app")).build();
    BundleModule featureModule = new BundleModuleBuilder("feature").addFile("lib/x86_64/libtest2.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)))).addFile("res/drawable-ldpi/image2.jpg").setResourceTable(resourceTable(pkg(USER_PACKAGE_OFFSET + 1, "com.test.app.split", type(0x01, "drawable", entry(0x01, "image2", fileReference("res/drawable-ldpi/image2.jpg", LDPI)))))).setManifest(androidManifestForFeature("com.test.app")).build();
    ImmutableList<ModuleSplit> shards = standaloneApksGenerator.generateStandaloneApks(ImmutableList.of(baseModule, featureModule), NO_DIMENSIONS);
    assertThat(shards).hasSize(1);
    ModuleSplit fatApk = shards.get(0);
    assertThat(extractPaths(fatApk.getEntries())).containsExactly("lib/x86_64/libtest1.so", "lib/x86_64/libtest2.so", "res/drawable-ldpi/image1.jpg", "res/drawable-ldpi/image2.jpg");
    assertThat(fatApk.getResourceTable()).isPresent();
    assertThat(fatApk.getResourceTable().get()).containsResource("com.test.app:drawable/image1").onlyWithConfigs(LDPI);
    assertThat(fatApk.getResourceTable().get()).containsResource("com.test.app.split:drawable/image2").onlyWithConfigs(LDPI);
}
Also used : 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)

Aggregations

BundleModule (com.android.tools.build.bundletool.model.BundleModule)404 Test (org.junit.Test)370 BundleModuleBuilder (com.android.tools.build.bundletool.testing.BundleModuleBuilder)321 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)158 InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)112 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)42 ResourceTable (com.android.aapt.Resources.ResourceTable)40 ApkTargeting (com.android.bundle.Targeting.ApkTargeting)29 ImmutableList (com.google.common.collect.ImmutableList)27 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)24 ImmutableSet (com.google.common.collect.ImmutableSet)22 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)21 DensityAlias (com.android.bundle.Targeting.ScreenDensity.DensityAlias)19 AppBundle (com.android.tools.build.bundletool.model.AppBundle)15 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)15 TestUtils.extractPaths (com.android.tools.build.bundletool.testing.TestUtils.extractPaths)15 Truth.assertThat (com.google.common.truth.Truth.assertThat)15 RunWith (org.junit.runner.RunWith)15 Assets (com.android.bundle.Files.Assets)14 VariantTargeting (com.android.bundle.Targeting.VariantTargeting)14