use of com.android.tools.build.bundletool.testing.BundleModuleBuilder in project bundletool by google.
the class ModuleSplitterTest method assetsLanguageSplitting.
@Test
public void assetsLanguageSplitting() throws Exception {
BundleModule testModule = new BundleModuleBuilder("testModule").addFile("assets/languages#lang_cz/pack.pak").addFile("assets/languages#lang_fr/pack.pak").addFile("dex/classes.dex").setAssetsConfig(assets(targetedAssetsDirectory("assets/languages#lang_cz", assetsDirectoryTargeting(languageTargeting("cz"))), targetedAssetsDirectory("assets/languages#lang_fr", assetsDirectoryTargeting(languageTargeting("fr"))))).setManifest(androidManifest("com.test.app")).build();
ImmutableList<ModuleSplit> splits = createAbiDensityAndLanguageSplitter(testModule).splitModule();
// FR, CZ 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> masterSplits = getSplitsWithTargetingEqualTo(splits, DEFAULT_MASTER_SPLIT_SDK_TARGETING);
assertThat(masterSplits).hasSize(1);
assertThat(extractPaths(masterSplits.get(0).getEntries())).containsExactly("dex/classes.dex");
ImmutableList<ModuleSplit> czSplits = getSplitsWithTargetingEqualTo(splits, mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkLanguageTargeting("cz")));
assertThat(czSplits).hasSize(1);
assertThat(extractPaths(czSplits.get(0).getEntries())).containsExactly("assets/languages#lang_cz/pack.pak");
ImmutableList<ModuleSplit> frSplits = getSplitsWithTargetingEqualTo(splits, mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkLanguageTargeting("fr")));
assertThat(frSplits).hasSize(1);
assertThat(extractPaths(frSplits.get(0).getEntries())).containsExactly("assets/languages#lang_fr/pack.pak");
}
use of com.android.tools.build.bundletool.testing.BundleModuleBuilder in project bundletool by google.
the class ScreenDensityResourcesSplitterTest method lowestDensityConfigsPinnedToMaster_mixedConfigsInSameDensityBucket.
@Test
public void lowestDensityConfigsPinnedToMaster_mixedConfigsInSameDensityBucket() throws Exception {
BundleModule testModule = new BundleModuleBuilder("testModule").addFile("res/drawable-ldpi/image.jpg").addFile("res/drawable-ldpi-v21/image.jpg").addFile("res/drawable-ldpi-v24/image.jpg").addFile("res/drawable-xxhdpi/image.jpg").addFile("res/drawable-xxhdpi-v21/image.jpg").addFile("res/drawable-xxhdpi-v24/image.jpg").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addFileResourceForMultipleConfigs("drawable", "image", ImmutableMap.<Configuration, String>builder().put(mergeConfigs(LDPI), "res/drawable-ldpi/image.jpg").put(mergeConfigs(LDPI, sdk(21)), "res/drawable-ldpi-v21/image.jpg").put(mergeConfigs(LDPI, sdk(24)), "res/drawable-ldpi-v24/image.jpg").put(mergeConfigs(XXXHDPI), "res/drawable-xxhdpi/image.jpg").put(mergeConfigs(XXHDPI, sdk(21)), "res/drawable-xxhdpi-v21/image.jpg").put(mergeConfigs(XXHDPI, sdk(24)), "res/drawable-xxhdpi-v24/image.jpg").build()).build()).setManifest(androidManifest("com.test.app")).build();
// 0x7f010000 is the "drawable/image" resource.
Predicate<ResourceId> pinnedLowDensityResourcesPredicate = resourceId -> resourceId.getFullResourceId() == 0x7f010000;
ScreenDensityResourcesSplitter splitter = new ScreenDensityResourcesSplitter(BundleToolVersion.getCurrentVersion(), NO_RESOURCES_PINNED_TO_MASTER, pinnedLowDensityResourcesPredicate, /* pinLowestBucketOfStylesToMaster= */
false);
ImmutableCollection<ModuleSplit> densitySplits = splitter.split(ModuleSplit.forResources(testModule));
ModuleSplit masterSplit = densitySplits.stream().filter(split -> split.isMasterSplit()).collect(onlyElement());
assertThat(extractPaths(masterSplit.getEntries())).containsExactly("res/drawable-ldpi/image.jpg", "res/drawable-ldpi-v21/image.jpg", "res/drawable-ldpi-v24/image.jpg");
ImmutableList<ModuleSplit> configSplits = densitySplits.stream().filter(split -> !split.isMasterSplit()).collect(toImmutableList());
assertThat(configSplits).isNotEmpty();
for (ModuleSplit configSplit : configSplits) {
assertThat(extractPaths(configSplit.getEntries())).containsNoneOf("res/drawable-ldpi/image.jpg", "res/drawable-ldpi-v21/image.jpg", "res/drawable-ldpi-v24/image.jpg");
}
}
use of com.android.tools.build.bundletool.testing.BundleModuleBuilder in project bundletool by google.
the class ScreenDensityResourcesSplitterTest method defaultDensityResourceWithoutAlternatives.
@Test
public void defaultDensityResourceWithoutAlternatives() throws Exception {
ResourceTable table = resourceTable(pkg(USER_PACKAGE_OFFSET, "com.test.app", type(0x01, "drawable", entry(0x01, "image", fileReference("res/drawable/image.jpg", Configuration.getDefaultInstance())))));
BundleModule module = new BundleModuleBuilder("base").addFile("res/drawable/image.jpg").setResourceTable(table).setManifest(androidManifest("com.test.app")).build();
ImmutableCollection<ModuleSplit> splits = splitter.split(ModuleSplit.forResources(module));
// No config split because the resource has no alternatives so ends up in the master split.
assertThat(splits).hasSize(1);
ModuleSplit masterSplit = findModuleSplitWithDefaultTargeting(splits);
assertThat(masterSplit.getResourceTable().get()).containsResource("com.test.app:drawable/image").onlyWithConfigs(Configuration.getDefaultInstance());
assertThat(masterSplit.findEntry("res/drawable/image.jpg")).isPresent();
}
use of com.android.tools.build.bundletool.testing.BundleModuleBuilder in project bundletool by google.
the class ScreenDensityResourcesSplitterTest method mipmapsNotIncludedInConfigSplits.
@Test
public void mipmapsNotIncludedInConfigSplits() throws Exception {
ResourceTable table = resourceTable(pkg(USER_PACKAGE_OFFSET, "com.test.app", type(0x01, "mipmap", entry(0x01, "launcher_icon", fileReference("res/mipmap-hdpi/launcher_icon.png", HDPI), fileReference("res/mipmap/launcher_icon.png", Configuration.getDefaultInstance()))), type(0x02, "drawable", entry(0x01, "image", fileReference("res/drawable-hdpi/image.jpg", HDPI), fileReference("res/drawable-xhdpi/image.jpg", XHDPI)))));
BundleModule testModule = new BundleModuleBuilder("testModule").addFile("res/mipmap/launcher_icon.png").addFile("res/mipmap-hdpi/launcher_icon.png").addFile("res/drawable-hdpi/image.jpg").addFile("res/drawable-xhdpi/image.jpg").setResourceTable(table).setManifest(androidManifest("com.test.app")).build();
ImmutableCollection<ModuleSplit> allSplits = splitter.split(ModuleSplit.forResources(testModule));
assertThat(allSplits).hasSize(DEFAULT_DENSITY_BUCKETS.size() + 1);
assertForSingleDefaultSplit(allSplits, defaultSplit -> {
assertThat(defaultSplit.getResourceTable()).isPresent();
ResourceTable defaultResourceTable = defaultSplit.getResourceTable().get();
assertThat(defaultResourceTable).containsResource("com.test.app:mipmap/launcher_icon").withConfigSize(2).withDensity(DEFAULT_DENSITY_VALUE).withDensity(HDPI_VALUE);
});
assertForNonDefaultSplits(allSplits, densitySplit -> {
assertThat(densitySplit.getResourceTable()).isPresent();
ResourceTable splitResourceTable = densitySplit.getResourceTable().get();
assertThat(splitResourceTable).doesNotContainResource("com.test.app:mipmap/launcher_icon");
});
}
use of com.android.tools.build.bundletool.testing.BundleModuleBuilder 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");
}
Aggregations