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");
}
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));
}
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);
}
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();
}
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);
}
Aggregations