use of com.android.bundle.Targeting.ApkTargeting in project bundletool by google.
the class MergingUtilsTest method mergeShardTargetings_firstAbiSecondLanguage_ok.
@Test
public void mergeShardTargetings_firstAbiSecondLanguage_ok() {
ApkTargeting targeting1 = apkAbiTargeting(AbiAlias.X86);
ApkTargeting targeting2 = apkLanguageTargeting("fr");
ApkTargeting merged = MergingUtils.mergeShardTargetings(targeting1, targeting2);
assertThat(merged).isEqualTo(ApkTargeting.newBuilder().setAbiTargeting(abiTargeting(AbiAlias.X86)).setLanguageTargeting(languageTargeting("fr")).build());
}
use of com.android.bundle.Targeting.ApkTargeting in project bundletool by google.
the class MergingUtilsTest method mergeShardTargetings_oneSubsetOfTheOther_ok.
@Test
public void mergeShardTargetings_oneSubsetOfTheOther_ok() {
ApkTargeting targeting1 = apkAbiTargeting(AbiAlias.X86);
ApkTargeting targeting2 = mergeApkTargeting(targeting1, apkDensityTargeting(DensityAlias.HDPI));
ApkTargeting merged = MergingUtils.mergeShardTargetings(targeting1, targeting2);
assertThat(merged).isEqualTo(targeting2);
}
use of com.android.bundle.Targeting.ApkTargeting in project bundletool by google.
the class MergingUtilsTest method mergeShardTargetings_differentAbis_ok.
@Test
public void mergeShardTargetings_differentAbis_ok() {
ApkTargeting targeting1 = apkAbiTargeting(AbiAlias.X86, ImmutableSet.of(AbiAlias.X86_64, AbiAlias.MIPS));
ApkTargeting targeting2 = apkAbiTargeting(AbiAlias.X86_64, ImmutableSet.of(AbiAlias.X86, AbiAlias.MIPS));
ApkTargeting merged = MergingUtils.mergeShardTargetings(targeting1, targeting2);
assertThat(merged).ignoringRepeatedFieldOrder().isEqualTo(apkAbiTargeting(ImmutableSet.of(AbiAlias.X86, AbiAlias.X86_64), ImmutableSet.of(AbiAlias.MIPS)));
}
use of com.android.bundle.Targeting.ApkTargeting in project bundletool by google.
the class MergingUtilsTest method mergeShardTargetings_nonAbiNonDensityNonLanguageTargeting_throws.
@Test
public void mergeShardTargetings_nonAbiNonDensityNonLanguageTargeting_throws() {
ApkTargeting targeting = apkMinSdkTargeting(21);
CommandExecutionException exception = assertThrows(CommandExecutionException.class, () -> MergingUtils.mergeShardTargetings(targeting, apkLanguageTargeting("en")));
assertThat(exception).hasMessageThat().contains("Expecting only ABI, screen density, language and texture compression format" + " targeting");
}
use of com.android.bundle.Targeting.ApkTargeting in project bundletool by google.
the class ModuleSplitsToShardMerger method mergeSingleShard.
/**
* Gets a list of splits, and merges them into a single standalone APK (aka shard).
*
* <p>Allows to customize split type {@code mergedSplitType} of merged shard and Android manifest
* merger {@code manifestMerger}.
*/
public ModuleSplit mergeSingleShard(ImmutableCollection<ModuleSplit> splitsOfShard, Map<ImmutableSet<ModuleEntry>, ImmutableList<Path>> mergedDexCache, SplitType mergedSplitType, AndroidManifestMerger manifestMerger) {
ListMultimap<BundleModuleName, ModuleEntry> dexFilesToMergeByModule = ArrayListMultimap.create();
// If multiple splits were generated from one module, we'll see the same manifest multiple
// times. The multimap filters out identical (module name, manifest) pairs by contract.
// All splits of a module should have the same manifest, so the following multimap should
// associate just one value with each key. This is checked explicitly for the base module
// because the manifest merger requires *single* base manifest.
SetMultimap<BundleModuleName, AndroidManifest> androidManifestsToMergeByModule = HashMultimap.create();
Map<ZipPath, ModuleEntry> mergedEntriesByPath = new HashMap<>();
Optional<ResourceTable> mergedResourceTable = Optional.empty();
Map<String, TargetedAssetsDirectory> mergedAssetsConfig = new HashMap<>();
ApkTargeting mergedSplitTargeting = ApkTargeting.getDefaultInstance();
for (ModuleSplit split : splitsOfShard) {
// Resource tables and Split targetings can be merged for each split individually as we go.
mergedResourceTable = mergeResourceTables(mergedResourceTable, split);
mergedSplitTargeting = mergeSplitTargetings(mergedSplitTargeting, split);
// Android manifests need to be merged later, globally for all splits.
androidManifestsToMergeByModule.put(split.getModuleName(), split.getAndroidManifest());
for (ModuleEntry entry : split.getEntries()) {
if (entry.getPath().startsWith(DEX_DIRECTORY)) {
// Dex files need to be merged later, globally for all splits.
dexFilesToMergeByModule.put(split.getModuleName(), entry);
} else {
mergeEntries(mergedEntriesByPath, split, entry);
}
}
split.getAssetsConfig().ifPresent(assetsConfig -> {
mergeTargetedAssetsDirectories(mergedAssetsConfig, assetsConfig.getDirectoryList());
});
}
AndroidManifest mergedAndroidManifest = manifestMerger.merge(androidManifestsToMergeByModule);
Collection<ModuleEntry> mergedDexFiles = mergeDexFilesAndCache(dexFilesToMergeByModule, mergedAndroidManifest, mergedDexCache);
// Record names of the modules this shard was fused from.
ImmutableList<String> fusedModuleNames = getUniqueModuleNames(splitsOfShard);
if (mergedSplitType.equals(SplitType.STANDALONE)) {
mergedAndroidManifest = mergedAndroidManifest.toEditor().setFusedModuleNames(fusedModuleNames).save();
}
// Construct the final shard.
return buildShard(mergedEntriesByPath.values(), mergedDexFiles, mergedSplitTargeting, mergedAndroidManifest, mergedResourceTable, mergedAssetsConfig, mergedSplitType);
}
Aggregations