Search in sources :

Example 46 with BundleModuleBuilder

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

the class LanguageResourcesSplitterTest method resourcesPinnedToMasterSplit_noSplitting_fileReferences.

@Test
public void resourcesPinnedToMasterSplit_noSplitting_fileReferences() throws Exception {
    ResourceTable resourceTable = new ResourceTableBuilder().addPackage("com.test.app").addResource("drawable", "image", fileReference("res/drawable-en-hdpi/image.jpg", mergeConfigs(locale("en"), HDPI)), fileReference("res/drawable-fr-hdpi/image.jpg", mergeConfigs(locale("fr"), HDPI))).addResource("drawable", "image2", fileReference("res/drawable-en-hdpi/image2.jpg", mergeConfigs(locale("en"), HDPI)), fileReference("res/drawable-fr-hdpi/image2.jpg", mergeConfigs(locale("fr"), HDPI))).build();
    BundleModule module = new BundleModuleBuilder("testModule").setResourceTable(resourceTable).setManifest(androidManifest("com.test.app")).addFile("res/drawable-en-hdpi/image.jpg").addFile("res/drawable-fr-hdpi/image.jpg").addFile("res/drawable-en-hdpi/image2.jpg").addFile("res/drawable-fr-hdpi/image2.jpg").build();
    ModuleSplit baseSplit = ModuleSplit.forResources(module);
    LanguageResourcesSplitter languageSplitter = new LanguageResourcesSplitter(resource -> resource.getResourceId().getFullResourceId() == 0x7f010000);
    Collection<ModuleSplit> languageSplits = languageSplitter.split(baseSplit);
    ModuleSplit masterSplit = languageSplits.stream().filter(split -> split.isMasterSplit()).collect(onlyElement());
    assertThat(masterSplit.getResourceTable()).hasValue(new ResourceTableBuilder().addPackage("com.test.app").addResource("drawable", "image", fileReference("res/drawable-en-hdpi/image.jpg", mergeConfigs(locale("en"), HDPI)), fileReference("res/drawable-fr-hdpi/image.jpg", mergeConfigs(locale("fr"), HDPI))).build());
    assertThat(extractPaths(masterSplit.getEntries())).containsExactly("res/drawable-en-hdpi/image.jpg", "res/drawable-fr-hdpi/image.jpg");
    ImmutableList<ModuleSplit> configSplits = languageSplits.stream().filter(split -> !split.isMasterSplit()).collect(toImmutableList());
    ImmutableMap<ApkTargeting, ModuleSplit> configSplitMap = Maps.uniqueIndex(configSplits, ModuleSplit::getApkTargeting);
    assertThat(configSplitMap.keySet()).containsExactly(apkLanguageTargeting("en"), apkLanguageTargeting("fr"));
    ModuleSplit enSplit = configSplitMap.get(apkLanguageTargeting("en"));
    assertThat(enSplit.getResourceTable()).hasValue(ResourcesTableFactory.createResourceTable(/* entryId= */
    0x01, "image2", fileReference("res/drawable-en-hdpi/image2.jpg", mergeConfigs(locale("en"), HDPI))));
    assertThat(extractPaths(enSplit.getEntries())).containsExactly("res/drawable-en-hdpi/image2.jpg");
    ModuleSplit frSplit = configSplitMap.get(apkLanguageTargeting("fr"));
    assertThat(frSplit.getResourceTable()).hasValue(ResourcesTableFactory.createResourceTable(/* entryId= */
    0x01, "image2", fileReference("res/drawable-fr-hdpi/image2.jpg", mergeConfigs(locale("fr"), HDPI))));
    assertThat(extractPaths(frSplit.getEntries())).containsExactly("res/drawable-fr-hdpi/image2.jpg");
}
Also used : Iterables(com.google.common.collect.Iterables) MDPI(com.android.tools.build.bundletool.testing.ResourcesTableFactory.MDPI) ApkTargeting(com.android.bundle.Targeting.ApkTargeting) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) ResourcesTableFactory.locale(com.android.tools.build.bundletool.testing.ResourcesTableFactory.locale) RunWith(org.junit.runner.RunWith) TestUtils.extractPaths(com.android.tools.build.bundletool.testing.TestUtils.extractPaths) ResourcesTableFactory.resourceTable(com.android.tools.build.bundletool.testing.ResourcesTableFactory.resourceTable) MoreCollectors.onlyElement(com.google.common.collect.MoreCollectors.onlyElement) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ProtoTruth.assertThat(com.google.common.truth.extensions.proto.ProtoTruth.assertThat) ImmutableList(com.google.common.collect.ImmutableList) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) ResourcesTableFactory.mergeConfigs(com.android.tools.build.bundletool.testing.ResourcesTableFactory.mergeConfigs) Map(java.util.Map) ResourcesTableFactory.entry(com.android.tools.build.bundletool.testing.ResourcesTableFactory.entry) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Predicates(com.google.common.base.Predicates) DensityAlias(com.android.bundle.Targeting.ScreenDensity.DensityAlias) ResourcesTableFactory.pkg(com.android.tools.build.bundletool.testing.ResourcesTableFactory.pkg) ResourcesTableFactory.type(com.android.tools.build.bundletool.testing.ResourcesTableFactory.type) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) ResourceTable(com.android.aapt.Resources.ResourceTable) ResourcesTableFactory.value(com.android.tools.build.bundletool.testing.ResourcesTableFactory.value) ConfigValue(com.android.aapt.Resources.ConfigValue) ImmutableMap(com.google.common.collect.ImmutableMap) USER_PACKAGE_OFFSET(com.android.tools.build.bundletool.testing.ResourcesTableFactory.USER_PACKAGE_OFFSET) HDPI(com.android.tools.build.bundletool.testing.ResourcesTableFactory.HDPI) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Collection(java.util.Collection) TestCase.fail(junit.framework.TestCase.fail) ResourcesTableFactory(com.android.tools.build.bundletool.testing.ResourcesTableFactory) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) SplitType(com.android.tools.build.bundletool.model.ModuleSplit.SplitType) Maps(com.google.common.collect.Maps) ResourcesTableFactory.fileReference(com.android.tools.build.bundletool.testing.ResourcesTableFactory.fileReference) TargetingUtils.apkDensityTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkDensityTargeting) ByteString(com.google.protobuf.ByteString) StringPool(com.android.aapt.Resources.StringPool) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) Ignore(org.junit.Ignore) TargetingUtils.mergeApkTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeApkTargeting) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Configuration(com.android.aapt.ConfigurationOuterClass.Configuration) TargetingUtils.apkLanguageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkLanguageTargeting) 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 47 with BundleModuleBuilder

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

the class ModuleSplitterTest method rPlusSigningConfigWithRPlusVariant_minSdkVersionInOutputTargetingGetsSetToR.

@Test
public void rPlusSigningConfigWithRPlusVariant_minSdkVersionInOutputTargetingGetsSetToR() throws Exception {
    BundleModule testModule = new BundleModuleBuilder("testModule").setManifest(androidManifest("com.test.app")).build();
    ImmutableList<ModuleSplit> moduleSplits = ModuleSplitter.createNoStamp(testModule, BUNDLETOOL_VERSION, APP_BUNDLE, ApkGenerationConfiguration.builder().setMinSdkForAdditionalVariantWithV3Rotation(ANDROID_R_API_VERSION).build(), variantMinSdkTargeting(Versions.ANDROID_R_API_VERSION), ImmutableSet.of("testModule")).splitModule();
    assertThat(moduleSplits.stream().map(ModuleSplit::getApkTargeting).distinct()).containsExactly(apkMinSdkTargeting(Versions.ANDROID_R_API_VERSION));
}
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 48 with BundleModuleBuilder

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

the class ModuleSplitterTest method masterSplit_hasAllOtherApkComponents.

@Test
public void masterSplit_hasAllOtherApkComponents() throws Exception {
    BundleModule testModule = new BundleModuleBuilder("testModule").setManifest(androidManifest("com.test.app")).addFile("assets/some_asset.txt").addFile("dex/classes.dex").addFile("root/some_other_file.txt").build();
    ImmutableList<ModuleSplit> splits = createAbiAndDensitySplitter(testModule).splitModule();
    assertThat(splits.stream().map(ModuleSplit::getSplitType).distinct().collect(toImmutableSet())).containsExactly(SplitType.SPLIT);
    assertThat(splits.stream().map(ModuleSplit::getVariantTargeting).distinct().collect(toImmutableSet())).containsExactly(lPlusVariantTargeting());
    // the example has nothing to split on.
    assertThat(splits).hasSize(1);
    ModuleSplit masterSplit = splits.get(0);
    assertThat(masterSplit.getApkTargeting()).isEqualTo(DEFAULT_MASTER_SPLIT_SDK_TARGETING);
    assertThat(masterSplit.isMasterSplit()).isTrue();
    ImmutableSet<String> actualFiles = masterSplit.getEntries().stream().map(ModuleEntry::getPath).map(ZipPath::toString).collect(toImmutableSet());
    ImmutableSet<String> expectedFiles = ImmutableSet.of("dex/classes.dex", "assets/some_asset.txt", "root/some_other_file.txt");
    assertThat(actualFiles).containsAtLeastElementsIn(expectedFiles);
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 49 with BundleModuleBuilder

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

the class ModuleSplitterTest method nativeSplits_lPlusTargeting_withDexCompressionSplitter.

@Test
public void nativeSplits_lPlusTargeting_withDexCompressionSplitter() throws Exception {
    BundleModule testModule = new BundleModuleBuilder("testModule").addFile("dex/classes.dex").setManifest(androidManifest("com.test.app")).build();
    ModuleSplitter moduleSplitter = ModuleSplitter.createNoStamp(testModule, BUNDLETOOL_VERSION, APP_BUNDLE, ApkGenerationConfiguration.builder().setEnableDexCompressionSplitter(true).build(), lPlusVariantTargeting(), ImmutableSet.of("testModule"));
    List<ModuleSplit> splits = moduleSplitter.splitModule();
    assertThat(splits).hasSize(1);
    ModuleSplit moduleSplit = Iterables.getOnlyElement(splits);
    assertThat(moduleSplit.getSplitType()).isEqualTo(SplitType.SPLIT);
    assertThat(moduleSplit.getVariantTargeting()).isEqualTo(variantMinSdkTargeting(ANDROID_L_API_VERSION));
    assertThat(moduleSplit.findEntry("dex/classes.dex").get().getForceUncompressed()).isFalse();
}
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 50 with BundleModuleBuilder

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

the class ModuleSplitterTest method instantManifestChanges_addsMinSdkVersion.

@Test
public void instantManifestChanges_addsMinSdkVersion() throws Exception {
    BundleModule bundleModule = new BundleModuleBuilder("testModule").setManifest(androidManifest("com.test.app", withInstant(true))).build();
    ImmutableList<ModuleSplit> moduleSplits = ModuleSplitter.createNoStamp(bundleModule, BUNDLETOOL_VERSION, APP_BUNDLE, ApkGenerationConfiguration.builder().setForInstantAppVariants(true).build(), lPlusVariantTargeting(), ImmutableSet.of("testModule")).splitModule();
    assertThat(moduleSplits).hasSize(1);
    ModuleSplit masterSplit = moduleSplits.get(0);
    assertThat(masterSplit.getVariantTargeting()).isEqualTo(lPlusVariantTargeting());
    assertThat(masterSplit.isMasterSplit()).isTrue();
    assertThat(masterSplit.getApkTargeting()).isEqualTo(apkMinSdkTargeting(21));
    assertThat(masterSplit.getSplitType()).isEqualTo(SplitType.INSTANT);
    assertThat(masterSplit.getAndroidManifest().getTargetSandboxVersion()).hasValue(2);
    assertThat(masterSplit.getAndroidManifest().getMinSdkVersion()).hasValue(21);
}
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