use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.
the class ModuleSplitterTest method manifestResourcePinning_langResourceWithoutDefaultConfig_pinned.
@Test
public void manifestResourcePinning_langResourceWithoutDefaultConfig_pinned() throws Exception {
BundleModule baseModule = new BundleModuleBuilder("base").setResourceTable(resourceTable(pkg(USER_PACKAGE_OFFSET, "com.test.app", type(0x01, "string", entry(0x0001, "welcome_label", value("Welcome", locale("en")), value("Willkommen", locale("de")), value("Здравствуйте", locale("ru"))), entry(0x0002, "goodbye_label", value("Goodbye", locale("en")), value("Auf Wiedersehen", locale("de")), value("До свидания", locale("ru"))))))).setManifest(androidManifest("com.test.app", withMetadataResource("reference-to-resource", 0x7f010001))).build();
ModuleSplitter moduleSplitter = ModuleSplitter.createNoStamp(baseModule, BUNDLETOOL_VERSION, APP_BUNDLE, ApkGenerationConfiguration.builder().setOptimizationDimensions(ImmutableSet.of(LANGUAGE)).setBaseManifestReachableResources(ImmutableSet.of(ResourceId.create(0x7f010001))).build(), lPlusVariantTargeting(), ImmutableSet.of("base"));
ImmutableList<ModuleSplit> splits = moduleSplitter.splitModule();
Map<String, ModuleSplit> splitsBySuffix = Maps.uniqueIndex(splits, ModuleSplit::getSuffix);
assertThat(splitsBySuffix.keySet()).containsExactly("en", "de", "ru", "");
assertThat(splitsBySuffix.get("").getResourceTable().get()).containsResource("com.test.app:string/welcome_label").onlyWithConfigs(locale("en"), locale("de"), locale("ru"));
assertThat(splitsBySuffix.get("en").getResourceTable().get()).doesNotContainResource("com.test.app:string/welcome_label");
assertThat(splitsBySuffix.get("de").getResourceTable().get()).doesNotContainResource("com.test.app:string/welcome_label");
assertThat(splitsBySuffix.get("ru").getResourceTable().get()).doesNotContainResource("com.test.app:string/welcome_label");
}
use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.
the class ModuleSplitterTest method targetsPreLOnlyInManifest_throws.
@Test
public void targetsPreLOnlyInManifest_throws() throws Exception {
int preL = 20;
BundleModule bundleModule = new BundleModuleBuilder("testModule").setManifest(androidManifest("com.test.app", withMaxSdkVersion(preL))).build();
CommandExecutionException exception = assertThrows(CommandExecutionException.class, () -> ModuleSplitter.createForTest(bundleModule, BUNDLETOOL_VERSION).splitModule());
assertThat(exception).hasMessageThat().contains("does not target devices on Android L or above");
}
use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.
the class ModuleSplitterTest method instantManifestChanges_updatesMinSdkVersion.
@Test
public void instantManifestChanges_updatesMinSdkVersion() throws Exception {
BundleModule bundleModule = new BundleModuleBuilder("testModule").setManifest(androidManifest("com.test.app", withMinSdkVersion(19), 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);
}
use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.
the class ModuleSplitterTest method instantManifestChanges_keepsMinSdkVersion.
@Test
public void instantManifestChanges_keepsMinSdkVersion() throws Exception {
BundleModule bundleModule = new BundleModuleBuilder("testModule").setManifest(androidManifest("com.test.app", withMinSdkVersion(22), 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(22);
}
use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.
the class ModuleSplitterTest method nativeSplits_mPlusTargeting_withAbiAndUncompressNativeLibsSplitter.
@Test
public void nativeSplits_mPlusTargeting_withAbiAndUncompressNativeLibsSplitter() throws Exception {
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.createNoStamp(testModule, BUNDLETOOL_VERSION, APP_BUNDLE, ApkGenerationConfiguration.builder().setOptimizationDimensions(ImmutableSet.of(ABI)).setEnableUncompressedNativeLibraries(true).build(), variantMinSdkTargeting(ANDROID_M_API_VERSION), ImmutableSet.of("testModule"));
List<ModuleSplit> splits = moduleSplitter.splitModule();
// Base + X86 Split
assertThat(splits).hasSize(2);
assertThat(splits.stream().map(ModuleSplit::getSplitType).distinct().collect(toImmutableSet())).containsExactly(SplitType.SPLIT);
assertThat(splits.stream().map(split -> split.getVariantTargeting()).collect(toImmutableSet())).containsExactly(variantMinSdkTargeting(ANDROID_M_API_VERSION));
ModuleSplit master = splits.stream().filter(ModuleSplit::isMasterSplit).collect(onlyElement());
ModuleSplit abi = splits.stream().filter(not(ModuleSplit::isMasterSplit)).collect(onlyElement());
assertThat(master.getAndroidManifest().getExtractNativeLibsValue()).hasValue(false);
assertThat(abi.findEntry("lib/x86/liba.so").get().getForceUncompressed()).isTrue();
}
Aggregations