Search in sources :

Example 86 with BundleModule

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

the class SplitApksGeneratorTest method multipleModules_withOnlyBaseModuleWithNativeLibraries.

@Test
public void multipleModules_withOnlyBaseModuleWithNativeLibraries() throws Exception {
    ImmutableList<BundleModule> bundleModule = ImmutableList.of(new BundleModuleBuilder("base").addFile("assets/leftover.txt").addFile("lib/x86_64/libsome.so").setManifest(androidManifest("com.test.app")).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(AbiAlias.X86_64)))).build(), new BundleModuleBuilder("test").addFile("assets/test.txt").setManifest(androidManifest("com.test.app")).build());
    ImmutableList<ModuleSplit> moduleSplits = splitApksGenerator.generateSplits(bundleModule, ApkGenerationConfiguration.builder().setEnableUncompressedNativeLibraries(true).build());
    VariantTargeting lVariantTargeting = variantMinSdkTargeting(/* minSdkVersion= */
    ANDROID_L_API_VERSION, /* alternativeSdkVersions...= */
    ANDROID_M_API_VERSION);
    VariantTargeting mVariantTargeting = variantMinSdkTargeting(/* minSdkVersion= */
    ANDROID_M_API_VERSION, /* alternativeSdkVersions...= */
    ANDROID_L_API_VERSION);
    // 2 splits for L and M variants.
    assertThat(moduleSplits).hasSize(4);
    assertThat(moduleSplits.stream().map(ModuleSplit::getVariantTargeting).collect(toImmutableSet())).containsExactly(lVariantTargeting, mVariantTargeting);
    ModuleSplit baseLModule = getModuleSplit(moduleSplits, lVariantTargeting, "base");
    assertThat(baseLModule.getSplitType()).isEqualTo(SplitType.SPLIT);
    assertThat(extractPaths(baseLModule.getEntries())).containsExactly("assets/leftover.txt", "lib/x86_64/libsome.so");
    assertThat(getForceUncompressed(baseLModule, "lib/x86_64/libsome.so")).isFalse();
    ModuleSplit testLModule = getModuleSplit(moduleSplits, lVariantTargeting, "test");
    assertThat(testLModule.getSplitType()).isEqualTo(SplitType.SPLIT);
    assertThat(extractPaths(testLModule.getEntries())).containsExactly("assets/test.txt");
    ModuleSplit baseMModule = getModuleSplit(moduleSplits, mVariantTargeting, "base");
    assertThat(baseMModule.getSplitType()).isEqualTo(SplitType.SPLIT);
    assertThat(extractPaths(baseMModule.getEntries())).containsExactly("assets/leftover.txt", "lib/x86_64/libsome.so");
    assertThat(getForceUncompressed(baseMModule, "lib/x86_64/libsome.so")).isTrue();
    ModuleSplit testMModule = getModuleSplit(moduleSplits, mVariantTargeting, "test");
    assertThat(testMModule.getSplitType()).isEqualTo(SplitType.SPLIT);
    assertThat(extractPaths(testMModule.getEntries())).containsExactly("assets/test.txt");
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) TargetingUtils.lPlusVariantTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.lPlusVariantTargeting) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 87 with BundleModule

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

the class SplitApksGeneratorTest method multipleModules_multipleVariants_withTransparency.

@Test
public void multipleModules_multipleVariants_withTransparency() throws Exception {
    TestComponent.useTestModule(this, TestModule.builder().withBundleMetadata(BUNDLE_METADATA_WITH_TRANSPARENCY).build());
    ImmutableList<BundleModule> bundleModule = ImmutableList.of(new BundleModuleBuilder("base").addFile("assets/leftover.txt").addFile("lib/x86_64/libsome.so").setManifest(androidManifest("com.test.app")).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(AbiAlias.X86_64)))).build(), new BundleModuleBuilder("test").addFile("assets/test.txt").setManifest(androidManifest("com.test.app")).build());
    ImmutableList<ModuleSplit> moduleSplits = splitApksGenerator.generateSplits(bundleModule, ApkGenerationConfiguration.builder().setOptimizationDimensions(ImmutableSet.of(OptimizationDimension.ABI)).build());
    ApkTargeting minSdkLTargeting = apkMinSdkTargeting(/* minSdkVersion= */
    ANDROID_L_API_VERSION);
    ApkTargeting minSdkLWithAbiTargeting = mergeApkTargeting(apkAbiTargeting(AbiAlias.X86_64), minSdkLTargeting);
    // 1 main and 1 ABI split for base module + test module.
    assertThat(moduleSplits).hasSize(3);
    assertThat(moduleSplits.stream().map(ModuleSplit::getApkTargeting).collect(toImmutableSet())).containsExactly(minSdkLTargeting, minSdkLWithAbiTargeting);
    ModuleSplit mainSplitOfBaseModule = getModuleSplit(moduleSplits, minSdkLTargeting, /* moduleName= */
    "base");
    assertThat(extractPaths(mainSplitOfBaseModule.getEntries())).containsExactly("assets/leftover.txt", "META-INF/code_transparency_signed.jwt");
    ModuleSplit abiSplitOfBaseModule = getModuleSplit(moduleSplits, minSdkLWithAbiTargeting, /* moduleName= */
    "base");
    assertThat(extractPaths(abiSplitOfBaseModule.getEntries())).containsExactly("lib/x86_64/libsome.so");
    ModuleSplit testModule = getModuleSplit(moduleSplits, minSdkLTargeting, /* moduleName= */
    "test");
    assertThat(extractPaths(testModule.getEntries())).containsExactly("assets/test.txt");
}
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) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 88 with BundleModule

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

the class TextureCompressionFormatAssetsSplitterTest method multipleTexturesAndDefaultSplit.

@Test
public void multipleTexturesAndDefaultSplit() throws Exception {
    BundleModule testModule = new BundleModuleBuilder("testModule").addFile("assets/images#tcf_etc1/image.jpg").addFile("assets/images#tcf_3dc/image.jpg").addFile("assets/file.txt").setAssetsConfig(assets(targetedAssetsDirectory("assets/images#tcf_etc1", assetsDirectoryTargeting(textureCompressionTargeting(TextureCompressionFormatAlias.ETC1_RGB8, ImmutableSet.of(TextureCompressionFormatAlias.THREE_DC)))), targetedAssetsDirectory("assets/images#tcf_3dc", assetsDirectoryTargeting(textureCompressionTargeting(TextureCompressionFormatAlias.THREE_DC, ImmutableSet.of(TextureCompressionFormatAlias.ETC1_RGB8)))), targetedAssetsDirectory("assets", AssetsDirectoryTargeting.getDefaultInstance()))).setManifest(androidManifest("com.test.app")).build();
    ModuleSplit baseSplit = ModuleSplit.forAssets(testModule);
    Collection<ModuleSplit> assetsSplits = TextureCompressionFormatAssetsSplitter.create(/* stripTargetingSuffix= */
    false).split(baseSplit);
    assertThat(assetsSplits).hasSize(3);
    List<ModuleSplit> defaultSplits = getSplitsWithDefaultTargeting(assetsSplits);
    assertThat(defaultSplits).hasSize(1);
    assertThat(extractPaths(defaultSplits.get(0).findEntriesUnderPath(ASSETS_DIRECTORY))).containsExactly("assets/file.txt");
    List<ModuleSplit> etc1Splits = getSplitsWithTargetingEqualTo(assetsSplits, apkTextureTargeting(textureCompressionTargeting(TextureCompressionFormatAlias.ETC1_RGB8, ImmutableSet.of(TextureCompressionFormatAlias.THREE_DC))));
    assertThat(etc1Splits).hasSize(1);
    assertThat(extractPaths(etc1Splits.get(0).findEntriesUnderPath(ASSETS_DIRECTORY))).containsExactly("assets/images#tcf_etc1/image.jpg");
    List<ModuleSplit> threeDcSplits = getSplitsWithTargetingEqualTo(assetsSplits, apkTextureTargeting(textureCompressionTargeting(TextureCompressionFormatAlias.THREE_DC, ImmutableSet.of(TextureCompressionFormatAlias.ETC1_RGB8))));
    assertThat(threeDcSplits).hasSize(1);
    assertThat(extractPaths(threeDcSplits.get(0).findEntriesUnderPath(ASSETS_DIRECTORY))).containsExactly("assets/images#tcf_3dc/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 89 with BundleModule

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

the class TextureCompressionFormatAssetsSplitterTest method manifestMutatorToRequireSplits_notRegistered_whenNoTcfSpecificAssets.

@Test
public void manifestMutatorToRequireSplits_notRegistered_whenNoTcfSpecificAssets() throws Exception {
    BundleModule testModule = new BundleModuleBuilder("testModule").addFile("assets/other/file.dat").setAssetsConfig(assets(targetedAssetsDirectory("assets/other", AssetsDirectoryTargeting.getDefaultInstance()))).setManifest(androidManifest("com.test.app")).build();
    ModuleSplit baseSplit = ModuleSplit.forAssets(testModule);
    ImmutableCollection<ModuleSplit> assetsSplits = TextureCompressionFormatAssetsSplitter.create(/* stripTargetingSuffix= */
    false).split(baseSplit);
    assertThat(assetsSplits).hasSize(1);
    assertThat(assetsSplits.asList().get(0).getMasterManifestMutators()).isEmpty();
}
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 90 with BundleModule

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

the class TextureCompressionFormatAssetsSplitterTest method manifestMutatorToRequireSplits_registered_whenTcfSpecificAssetsPresent.

@Test
public void manifestMutatorToRequireSplits_registered_whenTcfSpecificAssetsPresent() throws Exception {
    BundleModule testModule = new BundleModuleBuilder("testModule").addFile("assets/images#tcf_etc1/image.jpg").setAssetsConfig(assets(targetedAssetsDirectory("assets/images#tcf_etc1", assetsDirectoryTargeting(textureCompressionTargeting(TextureCompressionFormatAlias.ETC1_RGB8, ImmutableSet.of(TextureCompressionFormatAlias.THREE_DC)))))).setManifest(androidManifest("com.test.app")).build();
    ModuleSplit baseSplit = ModuleSplit.forAssets(testModule);
    ImmutableCollection<ModuleSplit> assetsSplits = TextureCompressionFormatAssetsSplitter.create(/* stripTargetingSuffix= */
    false).split(baseSplit);
    ImmutableList<ModuleSplit> configSplits = assetsSplits.stream().filter(split -> !split.isMasterSplit()).collect(toImmutableList());
    assertThat(configSplits).isNotEmpty();
    for (ModuleSplit configSplit : configSplits) {
        assertThat(compareManifestMutators(configSplit.getMasterManifestMutators(), withSplitsRequired(true))).isTrue();
    }
}
Also used : ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) TargetingUtils.textureCompressionTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.textureCompressionTargeting) RunWith(org.junit.runner.RunWith) TestUtils.extractPaths(com.android.tools.build.bundletool.testing.TestUtils.extractPaths) ImmutableCollection(com.google.common.collect.ImmutableCollection) TargetingUtils.getSplitsWithTargetingEqualTo(com.android.tools.build.bundletool.testing.TargetingUtils.getSplitsWithTargetingEqualTo) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ManifestMutator.withSplitsRequired(com.android.tools.build.bundletool.model.ManifestMutator.withSplitsRequired) ImmutableList(com.google.common.collect.ImmutableList) AssetsDirectoryTargeting(com.android.bundle.Targeting.AssetsDirectoryTargeting) TargetingUtils.targetedAssetsDirectory(com.android.tools.build.bundletool.testing.TargetingUtils.targetedAssetsDirectory) ImmutableSet(com.google.common.collect.ImmutableSet) ManifestProtoUtils.compareManifestMutators(com.android.tools.build.bundletool.testing.ManifestProtoUtils.compareManifestMutators) TargetingUtils.apkTextureTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkTextureTargeting) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Collection(java.util.Collection) Test(org.junit.Test) ASSETS_DIRECTORY(com.android.tools.build.bundletool.model.BundleModule.ASSETS_DIRECTORY) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) TargetingUtils.assets(com.android.tools.build.bundletool.testing.TargetingUtils.assets) List(java.util.List) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) TargetingUtils.getSplitsWithDefaultTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.getSplitsWithDefaultTargeting) TextureCompressionFormatAlias(com.android.bundle.Targeting.TextureCompressionFormat.TextureCompressionFormatAlias) TargetingUtils.assetsDirectoryTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.assetsDirectoryTargeting) BundleModule(com.android.tools.build.bundletool.model.BundleModule) 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