use of com.android.tools.build.bundletool.model.ModuleEntry in project bundletool by google.
the class SameTargetingMerger method mergeSplits.
private ModuleSplit mergeSplits(ImmutableCollection<ModuleSplit> splits) {
ModuleSplit.Builder builder = ModuleSplit.builder();
ImmutableList.Builder<ModuleEntry> entries = ImmutableList.builder();
AndroidManifest mergedManifest = null;
ResourceTable mergedResourceTable = null;
NativeLibraries mergedNativeConfig = null;
Map<String, TargetedAssetsDirectory> mergedAssetsConfig = new HashMap<>();
ApexImages mergedApexConfig = null;
ImmutableList<ApexEmbeddedApkConfig> mergedApexEmbeddedApkConfigs = null;
BundleModuleName mergedModuleName = null;
Boolean mergedIsMasterSplit = null;
VariantTargeting mergedVariantTargeting = null;
for (ModuleSplit split : splits) {
mergedManifest = getSameValueOrNonNull(mergedManifest, split.getAndroidManifest()).orElseThrow(() -> new IllegalStateException("Encountered two distinct manifests while merging."));
if (split.getResourceTable().isPresent()) {
mergedResourceTable = getSameValueOrNonNull(mergedResourceTable, split.getResourceTable().get()).orElseThrow(() -> new IllegalStateException("Unsupported case: encountered two distinct resource tables while " + "merging."));
}
if (split.getNativeConfig().isPresent()) {
mergedNativeConfig = getSameValueOrNonNull(mergedNativeConfig, split.getNativeConfig().get()).orElseThrow(() -> new IllegalStateException("Encountered two distinct native configs while merging."));
}
if (split.getApexConfig().isPresent()) {
mergedApexConfig = getSameValueOrNonNull(mergedApexConfig, split.getApexConfig().get()).orElseThrow(() -> new IllegalStateException("Encountered two distinct apex configs while merging."));
}
mergedApexEmbeddedApkConfigs = getSameValueOrNonNull(mergedApexEmbeddedApkConfigs, split.getApexEmbeddedApkConfigs()).orElseThrow(() -> new IllegalStateException("Encountered two distinct apex embedded apk configs while merging."));
mergedModuleName = getSameValueOrNonNull(mergedModuleName, split.getModuleName()).orElseThrow(() -> new IllegalStateException("Encountered two distinct module names while merging."));
mergedIsMasterSplit = getSameValueOrNonNull(mergedIsMasterSplit, Boolean.valueOf(split.isMasterSplit())).orElseThrow(() -> new IllegalStateException("Encountered conflicting isMasterSplit flag values while merging."));
mergedVariantTargeting = getSameValueOrNonNull(mergedVariantTargeting, split.getVariantTargeting()).orElseThrow(() -> new IllegalStateException("Encountered conflicting variant targeting values while merging."));
entries.addAll(split.getEntries());
builder.setApkTargeting(split.getApkTargeting());
split.getAssetsConfig().ifPresent(assetsConfig -> {
mergeTargetedAssetsDirectories(mergedAssetsConfig, assetsConfig.getDirectoryList());
});
}
if (mergedManifest != null) {
builder.setAndroidManifest(mergedManifest);
}
if (mergedResourceTable != null) {
builder.setResourceTable(mergedResourceTable);
}
if (mergedNativeConfig != null) {
builder.setNativeConfig(mergedNativeConfig);
}
if (!mergedAssetsConfig.isEmpty()) {
builder.setAssetsConfig(Assets.newBuilder().addAllDirectory(mergedAssetsConfig.values()).build());
}
if (mergedApexConfig != null) {
builder.setApexConfig(mergedApexConfig);
}
if (mergedApexEmbeddedApkConfigs != null) {
builder.setApexEmbeddedApkConfigs(mergedApexEmbeddedApkConfigs);
}
if (mergedModuleName != null) {
builder.setModuleName(mergedModuleName);
}
if (mergedIsMasterSplit != null) {
builder.setMasterSplit(mergedIsMasterSplit);
}
builder.setVariantTargeting(mergedVariantTargeting);
builder.setEntries(entries.build());
return builder.build();
}
use of com.android.tools.build.bundletool.model.ModuleEntry in project bundletool by google.
the class SystemApksGeneratorTest method uncompressedNativeLibraries_enabled_singleApk.
@Test
public void uncompressedNativeLibraries_enabled_singleApk() throws Exception {
BundleModule baseModule = new BundleModuleBuilder("base").addFile("assets/images/img.png").addFile("res/layout/default.xml").addFile("lib/x86_64/libtest1.so").addFile("lib/x86/libtest1.so").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addFileResource("layout", "default", "res/layout/default.xml").build()).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)), targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)))).setManifest(androidManifestForFeature("com.test.app")).build();
BundleModule featureModule = new BundleModuleBuilder("feature").addFile("lib/x86_64/libtest2.so").addFile("lib/x86/libtest2.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)), targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)))).setManifest(androidManifestForFeature("com.test.app.feature")).build();
ApkOptimizations apkOptimizations = splitOptimizations(OptimizationDimension.ABI).toBuilder().setUncompressNativeLibraries(true).build();
ImmutableList<ModuleSplit> shards = systemApksGenerator.generateSystemApks(/* modules= */
ImmutableList.of(baseModule, featureModule), /* modulesToFuse= */
ImmutableSet.of(BASE_MODULE_NAME, FEATURE_MODULE_NAME), apkOptimizations);
assertThat(shards).hasSize(1);
ModuleSplit fatApk = shards.get(0);
assertThat(fatApk.getAndroidManifest().getExtractNativeLibsValue()).hasValue(false);
assertThat(fatApk.findEntry("lib/x86/libtest1.so").map(ModuleEntry::getForceUncompressed)).hasValue(true);
assertThat(fatApk.findEntry("lib/x86/libtest2.so").map(ModuleEntry::getForceUncompressed)).hasValue(true);
assertThat(fatApk.findEntry("res/layout/default.xml").map(ModuleEntry::getForceUncompressed)).hasValue(false);
assertThat(fatApk.findEntry("assets/images/img.png").map(ModuleEntry::getForceUncompressed)).hasValue(false);
assertThat(fatApk.findEntry("lib/x86_64/libtest1.so")).isEmpty();
}
use of com.android.tools.build.bundletool.model.ModuleEntry in project bundletool by google.
the class SystemApksGeneratorTest method uncompressedNativeLibraries_enabled_multiApks.
@Test
public void uncompressedNativeLibraries_enabled_multiApks() throws Exception {
BundleModule baseModule = new BundleModuleBuilder("base").addFile("lib/x86_64/libtest1.so").addFile("lib/x86/libtest1.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)), targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)))).setManifest(androidManifestForFeature("com.test.app")).build();
BundleModule featureModule = new BundleModuleBuilder("feature").addFile("lib/x86_64/libtest2.so").addFile("lib/x86/libtest2.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)), targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)))).setManifest(androidManifestForFeature("com.test.app.feature")).build();
ApkOptimizations apkOptimizations = splitOptimizations(OptimizationDimension.ABI).toBuilder().setUncompressNativeLibraries(true).build();
ImmutableList<ModuleSplit> shards = systemApksGenerator.generateSystemApks(/* modules= */
ImmutableList.of(baseModule, featureModule), /* modulesToFuse= */
ImmutableSet.of(BASE_MODULE_NAME), apkOptimizations);
assertThat(shards).hasSize(3);
ModuleSplit systemApk = getSystemImageSplit(shards);
assertThat(systemApk.getAndroidManifest().getExtractNativeLibsValue()).hasValue(false);
assertThat(systemApk.findEntry("lib/x86/libtest1.so").map(ModuleEntry::getForceUncompressed)).hasValue(true);
ModuleSplit additionalNativeSplit = getAdditionalSplits(shards).stream().filter(split -> split.getApkTargeting().hasAbiTargeting()).collect(onlyElement());
assertThat(additionalNativeSplit.findEntry("lib/x86/libtest2.so").map(ModuleEntry::getForceUncompressed)).hasValue(true);
}
use of com.android.tools.build.bundletool.model.ModuleEntry in project bundletool by google.
the class SplitsXmlInjectorTest method process_noLanguageTargeting.
@Test
public void process_noLanguageTargeting() throws Exception {
ResourceTable baseResourceTable = new ResourceTableBuilder().addPackage("com.example.app").addStringResourceForMultipleLocales("title", ImmutableMap.of("ru", "title ru-RU", "fr", "title fr", "es", "title es")).build();
ModuleSplit baseModule = createModuleSplit(BASE_MODULE_NAME.getName(), /* splitId= */
"", /* masterSplit= */
true, SPLIT, /* languageTargeting= */
null).toBuilder().setResourceTable(baseResourceTable).build();
ResourceTable featureResourceTable = new ResourceTableBuilder().addPackage("com.example.app.module").addStringResourceForMultipleLocales("module_str", ImmutableMap.of("ru", "module ru-RU")).build();
ModuleSplit featureModule = createModuleSplit("module", /* splitId= */
"module", /* masterSplit= */
true, SPLIT, /* languageTargeting= */
null).toBuilder().setResourceTable(featureResourceTable).build();
GeneratedApks generatedApks = GeneratedApks.fromModuleSplits(ImmutableList.of(baseModule, featureModule));
ModuleSplit processedBaseMasterSplit = xmlInjectorProcess(generatedApks).stream().filter(module -> module.isMasterSplit() && module.isBaseModuleSplit()).collect(onlyElement());
assertThat(processedBaseMasterSplit.getResourceTable().get()).containsResource("com.example.app:xml/splits0").withFileReference("res/xml/splits0.xml");
XmlNode expectedSplitsProtoXml = new SplitsProtoXmlBuilder().addLanguageMapping(BundleModuleName.create("module"), "ru", "module").addLanguageMapping(BASE_MODULE_NAME, "ru", "").addLanguageMapping(BASE_MODULE_NAME, "fr", "").addLanguageMapping(BASE_MODULE_NAME, "es", "").build();
Optional<ModuleEntry> splitsXml = processedBaseMasterSplit.findEntry("res/xml/splits0.xml");
assertThat(splitsXml).isPresent();
assertThat(XmlNode.parseFrom(splitsXml.get().getContent().read(), ExtensionRegistry.getEmptyRegistry())).ignoringRepeatedFieldOrder().isEqualTo(expectedSplitsProtoXml);
}
use of com.android.tools.build.bundletool.model.ModuleEntry in project bundletool by google.
the class SystemApksGeneratorTest method uncompressedNativeLibraries_disabled.
@Test
public void uncompressedNativeLibraries_disabled() throws Exception {
BundleModule baseModule = new BundleModuleBuilder("base").addFile("lib/x86_64/libtest1.so").addFile("lib/x86/libtest1.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)), targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)))).setManifest(androidManifestForFeature("com.test.app")).build();
ApkOptimizations apkOptimizations = splitOptimizations(OptimizationDimension.ABI).toBuilder().setUncompressNativeLibraries(false).build();
ImmutableList<ModuleSplit> shards = systemApksGenerator.generateSystemApks(/* modules= */
ImmutableList.of(baseModule), /* modulesToFuse= */
ImmutableSet.of(BASE_MODULE_NAME), apkOptimizations);
assertThat(shards).hasSize(1);
ModuleSplit fatApk = shards.get(0);
assertThat(fatApk.getAndroidManifest().getExtractNativeLibsValue()).isEmpty();
assertThat(fatApk.findEntry("lib/x86/libtest1.so").map(ModuleEntry::getForceUncompressed)).hasValue(false);
assertThat(fatApk.findEntry("lib/x86_64/libtest1.so")).isEmpty();
}
Aggregations