use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.
the class SanitizerNativeLibrariesSplitterTest method splittingNoSanitizerLib.
@Test
public void splittingNoSanitizerLib() throws Exception {
NativeLibraries nativeConfig = nativeLibraries(targetedNativeDirectory("lib/arm64-v8a", nativeDirectoryTargeting(ARM64_V8A)), targetedNativeDirectory("lib/arm64-v8a-hwasan", nativeDirectoryTargeting(ARM64_V8A, HWADDRESS)));
BundleModule bundleModule = new BundleModuleBuilder("testModule").setNativeConfig(nativeConfig).addFile("lib/arm64-v8a/libtest.so").setManifest(androidManifest("com.test.app")).build();
SanitizerNativeLibrariesSplitter sanitizerNativeLibrariesSplitter = new SanitizerNativeLibrariesSplitter();
ModuleSplit mainSplit = ModuleSplit.forNativeLibraries(bundleModule).toBuilder().setApkTargeting(apkAbiTargeting(ARM64_V8A)).setMasterSplit(false).build();
ImmutableCollection<ModuleSplit> splits = sanitizerNativeLibrariesSplitter.split(mainSplit);
assertThat(splits).hasSize(1);
ModuleSplit nonHwasanSplit = splits.asList().get(0);
assertThat(nonHwasanSplit.getApkTargeting()).isEqualTo(apkAbiTargeting(ARM64_V8A));
assertThat(extractPaths(nonHwasanSplit.getEntries())).containsExactly("lib/arm64-v8a/libtest.so");
}
use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.
the class SanitizerNativeLibrariesSplitterTest method splittingBySanitizer.
@Test
public void splittingBySanitizer() throws Exception {
NativeLibraries nativeConfig = nativeLibraries(targetedNativeDirectory("lib/arm64-v8a", nativeDirectoryTargeting(ARM64_V8A)), targetedNativeDirectory("lib/arm64-v8a-hwasan", nativeDirectoryTargeting(ARM64_V8A, HWADDRESS)));
BundleModule bundleModule = new BundleModuleBuilder("testModule").setNativeConfig(nativeConfig).addFile("lib/arm64-v8a/libtest.so").addFile("lib/arm64-v8a-hwasan/libtest.so").setManifest(androidManifest("com.test.app")).build();
SanitizerNativeLibrariesSplitter sanitizerNativeLibrariesSplitter = new SanitizerNativeLibrariesSplitter();
ModuleSplit mainSplit = ModuleSplit.forNativeLibraries(bundleModule).toBuilder().setApkTargeting(apkAbiTargeting(ARM64_V8A)).setMasterSplit(false).build();
ImmutableCollection<ModuleSplit> splits = sanitizerNativeLibrariesSplitter.split(mainSplit);
assertThat(splits).hasSize(2);
ModuleSplit nonHwasanSplit = splits.asList().get(1);
assertThat(nonHwasanSplit.getApkTargeting()).isEqualTo(apkAbiTargeting(ARM64_V8A));
assertThat(extractPaths(nonHwasanSplit.getEntries())).containsExactly("lib/arm64-v8a/libtest.so");
ModuleSplit hwasanSplit = splits.asList().get(0);
assertThat(hwasanSplit.getApkTargeting()).isEqualTo(mergeApkTargeting(apkAbiTargeting(ARM64_V8A), apkSanitizerTargeting(HWADDRESS)));
assertThat(extractPaths(hwasanSplit.getEntries())).containsExactly("lib/arm64-v8a-hwasan/libtest.so");
}
use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.
the class ScreenDensityResourcesSplitterTest method complexDensitySplit.
@Test
public void complexDensitySplit() 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, "title_image", fileReference("res/drawable-hdpi/title_image.jpg", HDPI), fileReference("res/drawable-xhdpi/title_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/title_image.jpg").addFile("res/drawable-xhdpi/title_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 resourceTable = defaultSplit.getResourceTable().get();
assertThat(resourceTable).containsResource("com.test.app:mipmap/launcher_icon").withConfigSize(2).withDensity(HDPI_VALUE).withDensity(DEFAULT_DENSITY_VALUE);
assertThat(resourceTable).doesNotContainResource("com.test.app:drawable/title_image");
});
assertForNonDefaultSplits(allSplits, densitySplit -> {
assertThat(densitySplit.getResourceTable()).isPresent();
ResourceTable resourceTable = densitySplit.getResourceTable().get();
assertThat(resourceTable).hasPackage("com.test.app").withNoType("mipmap");
assertThat(resourceTable).containsResource("com.test.app:drawable/title_image").withConfigSize(1);
assertThat(densitySplit.getApkTargeting().hasScreenDensityTargeting()).isTrue();
switch(densitySplit.getApkTargeting().getScreenDensityTargeting().getValue(0).getDensityAlias()) {
case LDPI:
case MDPI:
case TVDPI:
case HDPI:
assertThat(resourceTable).containsResource("com.test.app:drawable/title_image").onlyWithConfigs(HDPI);
break;
case XHDPI:
case XXHDPI:
case XXXHDPI:
assertThat(resourceTable).containsResource("com.test.app:drawable/title_image").onlyWithConfigs(XHDPI);
break;
default:
fail(String.format("Unexpected targeting: %s", densitySplit.getApkTargeting()));
break;
}
});
}
use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.
the class ScreenDensityResourcesSplitterTest method lowestDensityStylesPinnedToMaster_disabled.
@Test
public void lowestDensityStylesPinnedToMaster_disabled() throws Exception {
BundleModule testModule = new BundleModuleBuilder("testModule").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addResource("style", "title_text_size", configValueWithDensity("320dens", Optional.of(XHDPI)), configValueWithDensity("default", Optional.empty())).build()).setManifest(androidManifest("com.test.app")).build();
ScreenDensityResourcesSplitter splitter = new ScreenDensityResourcesSplitter(BundleToolVersion.getCurrentVersion(), NO_RESOURCES_PINNED_TO_MASTER, NO_LOW_DENSITY_CONFIG_PINNED_TO_MASTER, /* pinLowestBucketOfStylesToMaster= */
false);
ImmutableCollection<ModuleSplit> splits = splitter.split(ModuleSplit.forResources(testModule));
ModuleSplit masterSplit = splits.stream().filter(ModuleSplit::isMasterSplit).collect(onlyElement());
assertThat(extractStyleValues(masterSplit, "title_text_size")).isEmpty();
ModuleSplit xhdpiSplit = extractDensityTargetingModule(splits, DensityAlias.XXHDPI).get();
assertThat(extractStyleValues(xhdpiSplit, "title_text_size")).containsExactly("320dens");
ModuleSplit mdpiSplit = extractDensityTargetingModule(splits, DensityAlias.MDPI).get();
assertThat(extractStyleValues(mdpiSplit, "title_text_size")).containsExactly("default");
}
use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.
the class ScreenDensityResourcesSplitterTest method twoDensitiesInSameBucket.
@Test
public void twoDensitiesInSameBucket() throws Exception {
ResourceTable table = resourceTable(pkg(USER_PACKAGE_OFFSET, "com.test.app", type(0x01, "drawable", entry(0x01, "image", fileReference("res/drawable-xxhdpi/image.png", XXHDPI), fileReference("res/drawable-560dpi/image.png", _560DPI), fileReference("res/drawable-xxxhdpi/image.png", XXXHDPI)))));
BundleModule module = new BundleModuleBuilder("base").addFile("res/drawable-xxhdpi/image.png").addFile("res/drawable-560dpi/image.png").addFile("res/drawable-xxxhdpi/image.png").setResourceTable(table).setManifest(androidManifest("com.test.app")).build();
ImmutableCollection<ModuleSplit> densitySplits = splitter.split(ModuleSplit.forResources(module));
ModuleSplit xxxhdpiSplit = findModuleSplitWithScreenDensityTargeting(densitySplits, ScreenDensity.newBuilder().setDensityAlias(DensityAlias.XXXHDPI).build());
assertThat(xxxhdpiSplit.getResourceTable()).isPresent();
ResourceTable resourceTable = xxxhdpiSplit.getResourceTable().get();
assertThat(resourceTable).containsResource("com.test.app:drawable/image").withConfigSize(2).withDensity(XXXHDPI_VALUE).withDensity(560);
}
Aggregations