use of com.android.bundle.Files.ApexImages in project bundletool by google.
the class BuildBundleCommandTest method validApexModuleWithBuildInfo.
@Test
public void validApexModuleWithBuildInfo() throws Exception {
XmlNode manifest = androidManifest(PKG_NAME, withHasCode(false));
ImmutableSet<AbiAlias> targetedAbis = ImmutableSet.of(X86_64, X86, ARM64_V8A, ARMEABI_V7A);
ApexImages apexConfig = apexImages(targetedImageWithBuildInfoAndAlternatives("apex/x86_64.img", "apex/x86_64.build_info.pb", X86_64, targetedAbis), targetedImageWithBuildInfoAndAlternatives("apex/x86.img", "apex/x86.build_info.pb", X86, targetedAbis), targetedImageWithBuildInfoAndAlternatives("apex/arm64-v8a.img", "apex/arm64-v8a.build_info.pb", ARM64_V8A, targetedAbis), targetedImageWithBuildInfoAndAlternatives("apex/armeabi-v7a.img", "apex/armeabi-v7a.build_info.pb", ARMEABI_V7A, targetedAbis));
byte[] apexManifest = "{\"name\": \"com.test.app\"}".getBytes(UTF_8);
Path module = new ZipBuilder().addFileWithContent(ZipPath.create("apex/x86_64.img"), "x86_64".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/x86_64.build_info.pb"), "x86_64.build_info".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/x86.img"), "x86".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/x86.build_info.pb"), "x86.build_info".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/arm64-v8a.img"), "arm64-v8a".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/arm64-v8a.build_info.pb"), "arm64-v8a.build_info".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/armeabi-v7a.img"), "armeabi-v7a".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/armeabi-v7a.build_info.pb"), "armeabi-v7a.build_info".getBytes(UTF_8)).addFileWithProtoContent(ZipPath.create("manifest/AndroidManifest.xml"), manifest).addFileWithContent(ZipPath.create("root/apex_manifest.json"), apexManifest).writeTo(tmpDir.resolve("base.zip"));
BuildBundleCommand.builder().setOutputPath(bundlePath).setModulesPaths(ImmutableList.of(module)).build().execute();
try (ZipFile bundle = new ZipFile(bundlePath.toFile())) {
assertThat(bundle).hasFile("base/manifest/AndroidManifest.xml").withContent(manifest.toByteArray());
assertThat(bundle).hasFile("base/apex/x86_64.img").withContent("x86_64".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/x86_64.build_info.pb").withContent("x86_64.build_info".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/x86.img").withContent("x86".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/x86.build_info.pb").withContent("x86.build_info".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/arm64-v8a.img").withContent("arm64-v8a".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/arm64-v8a.build_info.pb").withContent("arm64-v8a.build_info".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/armeabi-v7a.img").withContent("armeabi-v7a".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/armeabi-v7a.build_info.pb").withContent("armeabi-v7a.build_info".getBytes(UTF_8));
assertThat(bundle).hasFile("base/root/apex_manifest.json").withContent(apexManifest);
assertThat(bundle).hasFile("base/apex.pb").withContent(apexConfig.toByteArray());
}
}
use of com.android.bundle.Files.ApexImages 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.bundle.Files.ApexImages 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.Files.ApexImages 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.Files.ApexImages 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");
}
Aggregations