use of com.android.bundle.Targeting.ApkTargeting in project bundletool by google.
the class ModuleSplitsToShardMerger method mergeSingleApexShard.
@VisibleForTesting
ModuleSplit mergeSingleApexShard(ImmutableList<ModuleSplit> splitsOfShard) {
checkState(!splitsOfShard.isEmpty(), "A shard is made of at least one split.");
Map<ZipPath, ModuleEntry> mergedEntriesByPath = new HashMap<>();
ApkTargeting splitTargeting = ApkTargeting.getDefaultInstance();
for (ModuleSplit split : splitsOfShard) {
// An APEX shard is made of one master split and one multi-Abi split, so we use the latter.
splitTargeting = splitTargeting.hasMultiAbiTargeting() ? splitTargeting : split.getApkTargeting();
for (ModuleEntry entry : split.getEntries()) {
mergeEntries(mergedEntriesByPath, split, entry);
}
}
ModuleSplit shard = buildShard(mergedEntriesByPath.values(), ImmutableList.of(), splitTargeting, // An APEX module is made of one module, so any manifest works.
splitsOfShard.get(0).getAndroidManifest(), /* mergedResourceTable= */
Optional.empty(), /* mergedAssetsConfig= */
new HashMap<>(), /* mergedSplitType= */
SplitType.STANDALONE);
// Add the APEX config as it's used to identify APEX APKs.
return shard.toBuilder().setApexConfig(splitsOfShard.get(0).getApexConfig().get()).setApexEmbeddedApkConfigs(splitsOfShard.get(0).getApexEmbeddedApkConfigs()).build();
}
use of com.android.bundle.Targeting.ApkTargeting in project bundletool by google.
the class AbiApexImagesSplitterTest method splittingByMultipleAbi_multipleImageFiles.
@Test
public void splittingByMultipleAbi_multipleImageFiles() throws Exception {
ApexImages apexConfig = apexImages(targetedApexImage("apex/x86_64.x86.img", apexImageTargeting("x86_64", "x86")), targetedApexImage("apex/x86_64.armeabi-v7a.img", apexImageTargeting("x86_64", "armeabi-v7a")), targetedApexImage("apex/x86_64.img", apexImageTargeting("x86_64")), targetedApexImage("apex/x86.armeabi-v7a.img", apexImageTargeting("x86", "armeabi-v7a")), targetedApexImage("apex/x86.img", apexImageTargeting("x86")), targetedApexImage("apex/armeabi-v7a.img", apexImageTargeting("armeabi-v7a")));
BundleModule bundleModule = new BundleModuleBuilder("testModule").addFile("apex/x86_64.x86.img").addFile("apex/x86_64.armeabi-v7a.img").addFile("apex/x86_64.img").addFile("apex/x86.armeabi-v7a.img").addFile("apex/x86.img").addFile("apex/armeabi-v7a.img").setApexConfig(apexConfig).setManifest(androidManifest("com.test.app")).build();
AbiApexImagesSplitter abiApexImagesSplitter = new AbiApexImagesSplitter();
ImmutableCollection<ModuleSplit> splits = abiApexImagesSplitter.split(ModuleSplit.forApex(bundleModule));
assertThat(splits).hasSize(6);
ImmutableSet<AbiAlias> x64X86Set = ImmutableSet.of(X86, X86_64);
ImmutableSet<AbiAlias> x64ArmSet = ImmutableSet.of(ARMEABI_V7A, X86_64);
ImmutableSet<AbiAlias> x64Set = ImmutableSet.of(X86_64);
ImmutableSet<AbiAlias> x86ArmSet = ImmutableSet.of(ARMEABI_V7A, X86);
ImmutableSet<AbiAlias> x86Set = ImmutableSet.of(X86);
ImmutableSet<AbiAlias> armSet = ImmutableSet.of(ARMEABI_V7A);
ImmutableSet<ImmutableSet<AbiAlias>> allTargeting = ImmutableSet.of(armSet, x86ArmSet, x64ArmSet, x86Set, x64X86Set, x64Set);
ApkTargeting x64X86Targeting = apkMultiAbiTargetingFromAllTargeting(x64X86Set, allTargeting);
ApkTargeting x64ArmTargeting = apkMultiAbiTargetingFromAllTargeting(x64ArmSet, allTargeting);
ApkTargeting a64Targeting = apkMultiAbiTargetingFromAllTargeting(x64Set, allTargeting);
ApkTargeting x86ArmTargeting = apkMultiAbiTargetingFromAllTargeting(x86ArmSet, allTargeting);
ApkTargeting x86Targeting = apkMultiAbiTargetingFromAllTargeting(x86Set, allTargeting);
ApkTargeting armTargeting = apkMultiAbiTargetingFromAllTargeting(armSet, allTargeting);
ImmutableMap<ApkTargeting, ModuleSplit> splitsByTargeting = Maps.uniqueIndex(splits, ModuleSplit::getApkTargeting);
assertThat(splitsByTargeting.keySet()).containsExactly(x64X86Targeting, x64ArmTargeting, a64Targeting, x86ArmTargeting, x86Targeting, armTargeting);
assertThat(extractPaths(splitsByTargeting.get(x64X86Targeting).getEntries())).containsExactly("apex/x86_64.x86.img");
assertThat(extractPaths(splitsByTargeting.get(x64ArmTargeting).getEntries())).containsExactly("apex/x86_64.armeabi-v7a.img");
assertThat(extractPaths(splitsByTargeting.get(a64Targeting).getEntries())).containsExactly("apex/x86_64.img");
assertThat(extractPaths(splitsByTargeting.get(x86ArmTargeting).getEntries())).containsExactly("apex/x86.armeabi-v7a.img");
assertThat(extractPaths(splitsByTargeting.get(x86Targeting).getEntries())).containsExactly("apex/x86.img");
assertThat(extractPaths(splitsByTargeting.get(armTargeting).getEntries())).containsExactly("apex/armeabi-v7a.img");
}
use of com.android.bundle.Targeting.ApkTargeting in project bundletool by google.
the class AbiApexImagesSplitterTest method splittingBySingleAbi_twoImageFiles.
@Test
public void splittingBySingleAbi_twoImageFiles() throws Exception {
ApexImages apexConfig = apexImages(targetedApexImage("apex/x86.img", apexImageTargeting("x86")), targetedApexImage("apex/x86_64.img", apexImageTargeting("x86_64")));
BundleModule bundleModule = new BundleModuleBuilder("testModule").addFile("apex/x86.img").addFile("apex/x86_64.img").setApexConfig(apexConfig).setManifest(androidManifest("com.test.app")).build();
AbiApexImagesSplitter abiApexImagesSplitter = new AbiApexImagesSplitter();
ImmutableCollection<ModuleSplit> splits = abiApexImagesSplitter.split(ModuleSplit.forApex(bundleModule));
assertThat(splits).hasSize(2);
ApkTargeting x86Targeting = apkMultiAbiTargeting(X86, ImmutableSet.of(X86_64));
ApkTargeting x64Targeting = apkMultiAbiTargeting(X86_64, ImmutableSet.of(X86));
ImmutableMap<ApkTargeting, ModuleSplit> splitsByTargeting = Maps.uniqueIndex(splits, ModuleSplit::getApkTargeting);
assertThat(splitsByTargeting.keySet()).containsExactly(x86Targeting, x64Targeting);
assertThat(extractPaths(splitsByTargeting.get(x86Targeting).getEntries())).containsExactly("apex/x86.img");
assertThat(extractPaths(splitsByTargeting.get(x64Targeting).getEntries())).containsExactly("apex/x86_64.img");
}
use of com.android.bundle.Targeting.ApkTargeting in project bundletool by google.
the class StandaloneApexApksGeneratorTest method shardApexModule.
@Test
public void shardApexModule() throws Exception {
ApexImages apexConfig = apexImages(targetedApexImage("apex/x86_64.x86.img", apexImageTargeting("x86_64", "x86")), targetedApexImage("apex/x86_64.armeabi-v7a.img", apexImageTargeting("x86_64", "armeabi-v7a")), targetedApexImage("apex/x86_64.img", apexImageTargeting("x86_64")), targetedApexImage("apex/x86.armeabi-v7a.img", apexImageTargeting("x86", "armeabi-v7a")), targetedApexImage("apex/x86.img", apexImageTargeting("x86")), targetedApexImage("apex/armeabi-v7a.img", apexImageTargeting("armeabi-v7a")));
BundleModule apexModule = new BundleModuleBuilder("base").addFile("root/apex_manifest.json").addFile("apex/x86_64.x86.img").addFile("apex/x86_64.armeabi-v7a.img").addFile("apex/x86_64.img").addFile("apex/x86.armeabi-v7a.img").addFile("apex/x86.img").addFile("apex/armeabi-v7a.img").setManifest(androidManifest("com.test.app")).setApexConfig(apexConfig).build();
ImmutableList<ModuleSplit> shards = standaloneApexApksGenerator.generateStandaloneApks(ImmutableList.of(apexModule));
assertThat(shards).hasSize(6);
assertThat(shards.stream().map(ModuleSplit::getSplitType).distinct().collect(toImmutableSet())).containsExactly(SplitType.STANDALONE);
ImmutableSet<AbiAlias> x64X86Set = ImmutableSet.of(X86, X86_64);
ImmutableSet<AbiAlias> x64ArmSet = ImmutableSet.of(ARMEABI_V7A, X86_64);
ImmutableSet<AbiAlias> x64Set = ImmutableSet.of(X86_64);
ImmutableSet<AbiAlias> x86ArmSet = ImmutableSet.of(ARMEABI_V7A, X86);
ImmutableSet<AbiAlias> x86Set = ImmutableSet.of(X86);
ImmutableSet<AbiAlias> armSet = ImmutableSet.of(ARMEABI_V7A);
ImmutableSet<ImmutableSet<AbiAlias>> allTargeting = ImmutableSet.of(armSet, x86ArmSet, x64ArmSet, x86Set, x64X86Set, x64Set);
ApkTargeting x64X86Targeting = apkMultiAbiTargetingFromAllTargeting(x64X86Set, allTargeting);
ApkTargeting x64ArmTargeting = apkMultiAbiTargetingFromAllTargeting(x64ArmSet, allTargeting);
ApkTargeting a64Targeting = apkMultiAbiTargetingFromAllTargeting(x64Set, allTargeting);
ApkTargeting x86ArmTargeting = apkMultiAbiTargetingFromAllTargeting(x86ArmSet, allTargeting);
ApkTargeting x86Targeting = apkMultiAbiTargetingFromAllTargeting(x86Set, allTargeting);
ApkTargeting armTargeting = apkMultiAbiTargetingFromAllTargeting(armSet, allTargeting);
ImmutableMap<ApkTargeting, ModuleSplit> splitsByTargeting = Maps.uniqueIndex(shards, ModuleSplit::getApkTargeting);
assertThat(splitsByTargeting.keySet()).containsExactly(x64X86Targeting, x64ArmTargeting, a64Targeting, x86ArmTargeting, x86Targeting, armTargeting);
assertThat(shards.stream().map(ModuleSplit::getVariantTargeting).collect(toImmutableSet())).containsExactly(mergeVariantTargeting(variantMultiAbiTargetingFromAllTargeting(x64X86Set, allTargeting), variantMinSdkTargeting(1)), mergeVariantTargeting(variantMultiAbiTargetingFromAllTargeting(x64ArmSet, allTargeting), variantMinSdkTargeting(1)), mergeVariantTargeting(variantMultiAbiTargetingFromAllTargeting(x64Set, allTargeting), variantMinSdkTargeting(1)), mergeVariantTargeting(variantMultiAbiTargetingFromAllTargeting(x86ArmSet, allTargeting), variantMinSdkTargeting(1)), mergeVariantTargeting(variantMultiAbiTargetingFromAllTargeting(x86Set, allTargeting), variantMinSdkTargeting(1)), mergeVariantTargeting(variantMultiAbiTargetingFromAllTargeting(armSet, allTargeting), variantMinSdkTargeting(1)));
assertThat(extractPaths(splitsByTargeting.get(x64X86Targeting).getEntries())).containsExactly("root/apex_manifest.json", "apex/x86_64.x86.img");
assertThat(extractPaths(splitsByTargeting.get(x64ArmTargeting).getEntries())).containsExactly("root/apex_manifest.json", "apex/x86_64.armeabi-v7a.img");
assertThat(extractPaths(splitsByTargeting.get(a64Targeting).getEntries())).containsExactly("root/apex_manifest.json", "apex/x86_64.img");
assertThat(extractPaths(splitsByTargeting.get(x86ArmTargeting).getEntries())).containsExactly("root/apex_manifest.json", "apex/x86.armeabi-v7a.img");
assertThat(extractPaths(splitsByTargeting.get(x86Targeting).getEntries())).containsExactly("root/apex_manifest.json", "apex/x86.img");
assertThat(extractPaths(splitsByTargeting.get(armTargeting).getEntries())).containsExactly("root/apex_manifest.json", "apex/armeabi-v7a.img");
}
use of com.android.bundle.Targeting.ApkTargeting in project bundletool by google.
the class StandaloneApksGeneratorTest method manyModulesShardByAbi_havingManyAbis_producesManyApks.
@Test
public void manyModulesShardByAbi_havingManyAbis_producesManyApks() throws Exception {
BundleModule baseModule = new BundleModuleBuilder("base").addFile("dex/classes.dex").addFile("root/license.dat").setManifest(androidManifest("com.test.app")).build();
BundleModule featureModule1 = new BundleModuleBuilder("feature1").addFile("lib/x86/lib1.so").addFile("lib/x86_64/lib1.so").setManifest(androidManifest("com.test.app")).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)))).build();
BundleModule featureModule2 = new BundleModuleBuilder("feature2").addFile("lib/x86/lib2.so").addFile("lib/x86_64/lib2.so").setManifest(androidManifest("com.test.app")).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)))).build();
ImmutableList<ModuleSplit> shards = standaloneApksGenerator.generateStandaloneApks(ImmutableList.of(baseModule, featureModule1, featureModule2), standaloneApkOptimizations(OptimizationDimension.ABI));
assertThat(shards).hasSize(2);
assertThat(shards.stream().map(ModuleSplit::getSplitType).distinct().collect(toImmutableSet())).containsExactly(SplitType.STANDALONE);
assertThat(shards.stream().map(ModuleSplit::getVariantTargeting).distinct().collect(toImmutableSet())).containsExactly(mergeVariantTargeting(VARIANT_TARGETING_WITH_SDK_1, variantAbiTargeting(X86_64, ImmutableSet.of(X86))), mergeVariantTargeting(VARIANT_TARGETING_WITH_SDK_1, variantAbiTargeting(X86, ImmutableSet.of(X86_64))));
ImmutableMap<ApkTargeting, ModuleSplit> shardsByTargeting = Maps.uniqueIndex(shards, ModuleSplit::getApkTargeting);
ApkTargeting x86Targeting = apkAbiTargeting(X86, ImmutableSet.of(X86_64));
ApkTargeting x64Targeting = apkAbiTargeting(X86_64, ImmutableSet.of(X86));
assertThat(shardsByTargeting.keySet()).containsExactly(x86Targeting, x64Targeting);
assertThat(extractPaths(shardsByTargeting.get(x86Targeting).getEntries())).containsExactly("dex/classes.dex", "lib/x86/lib1.so", "lib/x86/lib2.so", "root/license.dat");
assertThat(extractPaths(shardsByTargeting.get(x64Targeting).getEntries())).containsExactly("dex/classes.dex", "lib/x86_64/lib1.so", "lib/x86_64/lib2.so", "root/license.dat");
}
Aggregations