use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.
the class ModuleSplitterTest method testModuleSplitter_nativeSplit_addsNoStamp.
@Test
public void testModuleSplitter_nativeSplit_addsNoStamp() throws Exception {
String stampSource = "https://www.example.com";
StampType stampType = StampType.STAMP_TYPE_DISTRIBUTION_APK;
NativeLibraries nativeConfig = nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting("x86")));
BundleModule testModule = new BundleModuleBuilder("testModule").setManifest(androidManifest("com.test.app")).setNativeConfig(nativeConfig).addFile("lib/x86/liba.so").build();
ModuleSplitter moduleSplitter = ModuleSplitter.create(testModule, BUNDLETOOL_VERSION, APP_BUNDLE, ApkGenerationConfiguration.builder().setOptimizationDimensions(ImmutableSet.of(ABI)).setEnableUncompressedNativeLibraries(true).build(), lPlusVariantTargeting(), ImmutableSet.of("testModule"), Optional.of(stampSource), stampType);
List<ModuleSplit> splits = moduleSplitter.splitModule();
// Base + x86 splits
assertThat(splits).hasSize(2);
ModuleSplit x86Split = splits.stream().filter(split -> split.getApkTargeting().hasAbiTargeting()).findFirst().get();
assertThat(x86Split.getAndroidManifest().getMetadataValue(STAMP_TYPE_METADATA_KEY)).isEmpty();
assertThat(x86Split.getAndroidManifest().getMetadataValue(STAMP_SOURCE_METADATA_KEY)).isEmpty();
}
use of com.android.tools.build.bundletool.model.BundleModule 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.model.BundleModule 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.model.BundleModule 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.model.BundleModule 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");
});
}
Aggregations