use of com.android.bundle.Targeting.Abi.AbiAlias in project bundletool by google.
the class AbiParityValidator method validateAllModules.
@Override
public void validateAllModules(ImmutableList<BundleModule> modules) {
BundleModule referentialModule = null;
Set<AbiAlias> referentialAbis = null;
for (BundleModule module : modules) {
ImmutableSet<AbiAlias> moduleAbis = getSupportedAbis(module);
if (moduleAbis.isEmpty()) {
continue;
}
if (referentialAbis == null) {
referentialModule = module;
referentialAbis = moduleAbis;
} else if (!referentialAbis.equals(moduleAbis)) {
throw InvalidBundleException.builder().withUserMessage("All modules with native libraries must support the same set of ABIs, but" + " module '%s' supports '%s' and module '%s' supports '%s'.", referentialModule.getName(), referentialAbis, module.getName(), moduleAbis).build();
}
}
}
use of com.android.bundle.Targeting.Abi.AbiAlias in project bundletool by google.
the class SameTargetingMergerTest method sameSplitTargeting_multipleGroups.
@Test
public void sameSplitTargeting_multipleGroups() throws Exception {
ImmutableSet<AbiAlias> abis = ImmutableSet.of(AbiAlias.X86, AbiAlias.ARMEABI_V7A, AbiAlias.MIPS);
ModuleSplit moduleSplit = createModuleSplitBuilder().setEntries(ImmutableList.of(createModuleEntryForFile("testModule/lib/x86/liba.so", DUMMY_CONTENT))).setMasterSplit(false).setApkTargeting(apkAbiTargeting(ImmutableSet.of(AbiAlias.X86), abis)).build();
ModuleSplit moduleSplit2 = createModuleSplitBuilder().setEntries(ImmutableList.of(createModuleEntryForFile("testModule/lib/armv7-eabi/liba.so", DUMMY_CONTENT))).setMasterSplit(false).setApkTargeting(apkAbiTargeting(ImmutableSet.of(AbiAlias.ARMEABI), abis)).build();
ModuleSplit moduleSplit3 = createModuleSplitBuilder().setEntries(ImmutableList.of(createModuleEntryForFile("testModule/lib/mips/liba.so", DUMMY_CONTENT))).setMasterSplit(false).setApkTargeting(apkAbiTargeting(ImmutableSet.of(AbiAlias.MIPS), abis)).build();
ModuleSplit moduleSplit4 = createModuleSplitBuilder().setEntries(ImmutableList.of(createModuleEntryForFile("testModule/lib/x86/libb.so", DUMMY_CONTENT))).setMasterSplit(false).setApkTargeting(apkAbiTargeting(ImmutableSet.of(AbiAlias.X86), abis)).build();
ModuleSplit moduleSplit5 = createModuleSplitBuilder().setEntries(ImmutableList.of(createModuleEntryForFile("testModule/lib/armv7-eabi/libb.so", DUMMY_CONTENT))).setMasterSplit(false).setApkTargeting(apkAbiTargeting(ImmutableSet.of(AbiAlias.ARMEABI), abis)).build();
ModuleSplit moduleSplit6 = createModuleSplitBuilder().setEntries(ImmutableList.of(createModuleEntryForFile("testModule/lib/mips/libb.so", DUMMY_CONTENT))).setMasterSplit(false).setApkTargeting(apkAbiTargeting(ImmutableSet.of(AbiAlias.MIPS), abis)).build();
SameTargetingMerger merger = new SameTargetingMerger();
ImmutableCollection<ModuleSplit> splits = merger.merge(ImmutableList.of(moduleSplit, moduleSplit2, moduleSplit3, moduleSplit4, moduleSplit5, moduleSplit6));
assertThat(splits).hasSize(3);
assertThat(splits.stream().map(ModuleSplit::getApkTargeting).collect(toImmutableList())).ignoringRepeatedFieldOrder().containsExactly(apkAbiTargeting(ImmutableSet.of(AbiAlias.MIPS), abis), apkAbiTargeting(ImmutableSet.of(AbiAlias.X86), abis), apkAbiTargeting(ImmutableSet.of(AbiAlias.ARMEABI), abis));
assertThat(splits.stream().map(ModuleSplit::getVariantTargeting).distinct().collect(toImmutableSet())).containsExactly(lPlusVariantTargeting());
}
use of com.android.bundle.Targeting.Abi.AbiAlias in project bundletool by google.
the class BuildBundleCommandTest method validApexModule.
@Test
public void validApexModule() throws Exception {
XmlNode manifest = androidManifest(PKG_NAME, withHasCode(false));
ImmutableSet<AbiAlias> targetedAbis = ImmutableSet.of(X86_64, X86, ARM64_V8A, ARMEABI_V7A);
ApexImages apexConfig = apexImages(targetedImageWithAlternatives("apex/x86_64.img", X86_64, targetedAbis), targetedImageWithAlternatives("apex/x86.img", X86, targetedAbis), targetedImageWithAlternatives("apex/arm64-v8a.img", ARM64_V8A, targetedAbis), targetedImageWithAlternatives("apex/armeabi-v7a.img", 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.img"), "x86".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/arm64-v8a.img"), "arm64-v8a".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/armeabi-v7a.img"), "armeabi-v7a".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.img").withContent("x86".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/arm64-v8a.img").withContent("arm64-v8a".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/armeabi-v7a.img").withContent("armeabi-v7a".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.Targeting.Abi.AbiAlias 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.Targeting.Abi.AbiAlias 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");
}
Aggregations