Search in sources :

Example 86 with BundleModuleBuilder

use of com.android.tools.build.bundletool.testing.BundleModuleBuilder in project bundletool by google.

the class SystemApksGeneratorTest method manyModulesShardByAbiAndDensity_havingManyAbisAndSomeResourceWithDeviceSpec_producesSingleApk.

@Test
public void manyModulesShardByAbiAndDensity_havingManyAbisAndSomeResourceWithDeviceSpec_producesSingleApk() throws Exception {
    BundleModule baseModule = new BundleModuleBuilder("base").addFile("assets/file.txt").addFile("dex/classes.dex").addFile("res/drawable/image.jpg").addFile("res/drawable-hdpi/image.jpg").addFile("root/license.dat").setManifest(androidManifest("com.test.app")).setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("image", ImmutableMap.of(DEFAULT_DENSITY_VALUE, "res/drawable/image.jpg", HDPI_VALUE, "res/drawable-hdpi/image.jpg")).build()).build();
    BundleModule featureModule = new BundleModuleBuilder("feature").addFile("lib/armeabi/libtest.so").addFile("lib/x86/libtest.so").setManifest(androidManifestForFeature("com.test.app")).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/armeabi", nativeDirectoryTargeting(ARMEABI)), targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)))).build();
    ImmutableList<ModuleSplit> shards = systemApksGenerator.generateSystemApks(/* modules= */
    ImmutableList.of(baseModule, featureModule), /* modulesToFuse= */
    ImmutableSet.of(BASE_MODULE_NAME, FEATURE_MODULE_NAME), splitOptimizations(OptimizationDimension.ABI, OptimizationDimension.SCREEN_DENSITY));
    ModuleSplit fatShard = getSystemImageSplit(shards);
    assertThat(fatShard.getApkTargeting().getAbiTargeting()).isEqualTo(abiTargeting(X86, ImmutableSet.of(ARMEABI)));
    assertThat(fatShard.getApkTargeting().getScreenDensityTargeting().getValueList()).containsExactly(toScreenDensity(DensityAlias.MDPI));
    assertThat(fatShard.getSplitType()).isEqualTo(SplitType.SYSTEM);
    assertThat(fatShard.isBaseModuleSplit()).isTrue();
    assertThat(extractPaths(fatShard.getEntries())).containsExactly("assets/file.txt", "dex/classes.dex", "lib/x86/libtest.so", "res/drawable/image.jpg", "root/license.dat");
    assertThat(shards).hasSize(1);
}
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 87 with BundleModuleBuilder

use of com.android.tools.build.bundletool.testing.BundleModuleBuilder in project bundletool by google.

the class SystemApksGeneratorTest method producesTwoApks_withTransparency.

@Test
public void producesTwoApks_withTransparency() throws Exception {
    TestComponent.useTestModule(this, TestModule.builder().withBundleMetadata(BUNDLE_METADATA_WITH_TRANSPARENCY).withDeviceSpec(DEVICE_SPEC).build());
    BundleModule baseModule = new BundleModuleBuilder("base").addFile("assets/languages#lang_fr/image.jpg").setAssetsConfig(assets(targetedAssetsDirectory("assets/languages#lang_fr", assetsDirectoryTargeting(languageTargeting("fr"))))).setManifest(androidManifest("com.app")).build();
    BundleModule vrModule = new BundleModuleBuilder("vr").addFile("assets/vr/languages#lang_fr/image.jpg").setAssetsConfig(assets(targetedAssetsDirectory("assets/vr/languages#lang_fr", assetsDirectoryTargeting(languageTargeting("fr"))))).setManifest(androidManifestForFeature("com.app", withFusingAttribute(true), withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID))).build();
    ImmutableList<ModuleSplit> shards = systemApksGenerator.generateSystemApks(/* modules= */
    ImmutableList.of(baseModule, vrModule), /* modulesToFuse= */
    ImmutableSet.of(BASE_MODULE_NAME, VR_MODULE_NAME), splitOptimizations(OptimizationDimension.LANGUAGE));
    assertThat(shards).hasSize(2);
    ModuleSplit fusedShard = shards.get(0);
    assertThat(fusedShard.isBaseModuleSplit()).isTrue();
    assertThat(extractPaths(fusedShard.getEntries())).containsExactly("META-INF/code_transparency_signed.jwt");
    ModuleSplit languageSplit = shards.get(1);
    assertThat(extractPaths(languageSplit.getEntries())).containsExactly("assets/languages#lang_fr/image.jpg", "assets/vr/languages#lang_fr/image.jpg");
}
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)

Example 88 with BundleModuleBuilder

use of com.android.tools.build.bundletool.testing.BundleModuleBuilder in project bundletool by google.

the class SystemApksGeneratorTest method uncompressedDexFiles_enabled.

@Test
public void uncompressedDexFiles_enabled() throws Exception {
    BundleModule baseModule = new BundleModuleBuilder("base").addFile("dex/classes.dex").setManifest(androidManifestForFeature("com.test.app")).build();
    ApkOptimizations apkOptimizations = splitOptimizations().toBuilder().setUncompressDexFiles(true).build();
    ImmutableList<ModuleSplit> shards = systemApksGenerator.generateSystemApks(/* modules= */
    ImmutableList.of(baseModule), /* modulesToFuse= */
    ImmutableSet.of(BASE_MODULE_NAME), apkOptimizations);
    assertThat(shards).hasSize(1);
    ModuleSplit fatApk = shards.get(0);
    assertThat(fatApk.findEntry("dex/classes.dex").map(ModuleEntry::getForceUncompressed)).hasValue(true);
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ApkOptimizations(com.android.tools.build.bundletool.optimizations.ApkOptimizations) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 89 with BundleModuleBuilder

use of com.android.tools.build.bundletool.testing.BundleModuleBuilder in project bundletool by google.

the class SystemApksGeneratorTest 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/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)))).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 = systemApksGenerator.generateSystemApks(/* modules= */
    ImmutableList.of(bundleModule), /* modulesToFuse= */
    ImmutableSet.of(BASE_MODULE_NAME), splitOptimizations(OptimizationDimension.ABI));
    assertThat(shards).hasSize(1);
    ModuleSplit fatShard = shards.get(0);
    assertThat(fatShard.getApkTargeting()).isEqualTo(apkAbiTargeting(X86));
    assertThat(fatShard.getVariantTargeting()).isEqualTo(mergeVariantTargeting(variantMinSdkTargeting(1), variantAbiTargeting(X86)));
    assertThat(fatShard.getSplitType()).isEqualTo(SplitType.SYSTEM);
    assertThat(extractPaths(fatShard.getEntries())).containsExactly("assets/file.txt", "dex/classes.dex", "lib/x86/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 90 with BundleModuleBuilder

use of com.android.tools.build.bundletool.testing.BundleModuleBuilder in project bundletool by google.

the class ModuleSplitterTest method deviceTierAsset_splitting_and_merging.

@Test
public void deviceTierAsset_splitting_and_merging() {
    BundleModule testModule = new BundleModuleBuilder("testModule").addFile("assets/main#tier_0/image.jpg").addFile("assets/main#tier_1/image.jpg").addFile("dex/classes.dex").setAssetsConfig(assets(targetedAssetsDirectory("assets/main#tier_0", assetsDirectoryTargeting(deviceTierTargeting(/* value= */
    0, /* alternatives= */
    ImmutableList.of(1)))), targetedAssetsDirectory("assets/main#tier_1", assetsDirectoryTargeting(deviceTierTargeting(/* value= */
    1, /* alternatives= */
    ImmutableList.of(0)))))).setManifest(androidManifest("com.test.app")).build();
    ImmutableList<ModuleSplit> splits = createDeviceTierSplitter(testModule).splitModule();
    // expected 3 splits: low tier, medium tier and the master split.
    assertThat(splits).hasSize(3);
    assertThat(splits.stream().map(ModuleSplit::getSplitType).distinct().collect(toImmutableSet())).containsExactly(SplitType.SPLIT);
    assertThat(splits.stream().map(ModuleSplit::getVariantTargeting).distinct().collect(toImmutableSet())).containsExactly(lPlusVariantTargeting());
    ImmutableList<ModuleSplit> defaultSplits = getSplitsWithTargetingEqualTo(splits, DEFAULT_MASTER_SPLIT_SDK_TARGETING);
    assertThat(defaultSplits).hasSize(1);
    assertThat(extractPaths(defaultSplits.get(0).getEntries())).containsExactly("dex/classes.dex");
    ImmutableList<ModuleSplit> lowTierSplits = getSplitsWithTargetingEqualTo(splits, mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkDeviceTierTargeting(deviceTierTargeting(/* value= */
    0, /* alternatives= */
    ImmutableList.of(1)))));
    assertThat(lowTierSplits).hasSize(1);
    assertThat(extractPaths(lowTierSplits.get(0).getEntries())).containsExactly("assets/main#tier_0/image.jpg");
    ImmutableList<ModuleSplit> mediumTierSplits = getSplitsWithTargetingEqualTo(splits, mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkDeviceTierTargeting(deviceTierTargeting(/* value= */
    1, /* alternatives= */
    ImmutableList.of(0)))));
    assertThat(mediumTierSplits).hasSize(1);
    assertThat(extractPaths(mediumTierSplits.get(0).getEntries())).containsExactly("assets/main#tier_1/image.jpg");
}
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

BundleModuleBuilder (com.android.tools.build.bundletool.testing.BundleModuleBuilder)349 Test (org.junit.Test)348 BundleModule (com.android.tools.build.bundletool.model.BundleModule)321 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)164 InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)69 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)44 ResourceTable (com.android.aapt.Resources.ResourceTable)38 ApkTargeting (com.android.bundle.Targeting.ApkTargeting)28 DensityAlias (com.android.bundle.Targeting.ScreenDensity.DensityAlias)19 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)16 Truth.assertThat (com.google.common.truth.Truth.assertThat)16 RunWith (org.junit.runner.RunWith)16 TestUtils.extractPaths (com.android.tools.build.bundletool.testing.TestUtils.extractPaths)15 ImmutableList (com.google.common.collect.ImmutableList)15 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)15 ProtoTruth.assertThat (com.google.common.truth.extensions.proto.ProtoTruth.assertThat)15 Truth8.assertThat (com.google.common.truth.Truth8.assertThat)14 NativeLibraries (com.android.bundle.Files.NativeLibraries)13 HDPI (com.android.tools.build.bundletool.testing.ResourcesTableFactory.HDPI)13 USER_PACKAGE_OFFSET (com.android.tools.build.bundletool.testing.ResourcesTableFactory.USER_PACKAGE_OFFSET)13