Search in sources :

Example 1 with AbiAlias

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();
        }
    }
}
Also used : AbiAlias(com.android.bundle.Targeting.Abi.AbiAlias) BundleModule(com.android.tools.build.bundletool.model.BundleModule)

Example 2 with AbiAlias

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());
}
Also used : ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) AbiAlias(com.android.bundle.Targeting.Abi.AbiAlias) Test(org.junit.Test)

Example 3 with AbiAlias

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());
    }
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) XmlNode(com.android.aapt.Resources.XmlNode) ApexImages(com.android.bundle.Files.ApexImages) ZipFile(java.util.zip.ZipFile) ZipBuilder(com.android.tools.build.bundletool.io.ZipBuilder) AbiAlias(com.android.bundle.Targeting.Abi.AbiAlias) Test(org.junit.Test)

Example 4 with AbiAlias

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());
    }
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) XmlNode(com.android.aapt.Resources.XmlNode) ApexImages(com.android.bundle.Files.ApexImages) ZipFile(java.util.zip.ZipFile) ZipBuilder(com.android.tools.build.bundletool.io.ZipBuilder) AbiAlias(com.android.bundle.Targeting.Abi.AbiAlias) Test(org.junit.Test)

Example 5 with AbiAlias

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");
}
Also used : ApexImages(com.android.bundle.Files.ApexImages) ImmutableSet(com.google.common.collect.ImmutableSet) ApkTargeting(com.android.bundle.Targeting.ApkTargeting) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) AbiAlias(com.android.bundle.Targeting.Abi.AbiAlias) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Aggregations

AbiAlias (com.android.bundle.Targeting.Abi.AbiAlias)9 Test (org.junit.Test)7 ApexImages (com.android.bundle.Files.ApexImages)6 ApkTargeting (com.android.bundle.Targeting.ApkTargeting)4 ZipPath (com.android.tools.build.bundletool.model.ZipPath)4 ImmutableSet (com.google.common.collect.ImmutableSet)4 Path (java.nio.file.Path)4 ZipFile (java.util.zip.ZipFile)4 BundleModule (com.android.tools.build.bundletool.model.BundleModule)3 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)3 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)3 Configuration (com.android.aapt.ConfigurationOuterClass.Configuration)2 XmlNode (com.android.aapt.Resources.XmlNode)2 ApexManifest (com.android.apex.ApexManifestProto.ApexManifest)2 ApkVerifier (com.android.apksig.ApkVerifier)2 CodeRelatedFile (com.android.bundle.CodeTransparencyOuterClass.CodeRelatedFile)2 CodeTransparency (com.android.bundle.CodeTransparencyOuterClass.CodeTransparency)2 ApkDescription (com.android.bundle.Commands.ApkDescription)2 ApkSet (com.android.bundle.Commands.ApkSet)2 AssetModulesInfo (com.android.bundle.Commands.AssetModulesInfo)2