Search in sources :

Example 1 with MultiAbiTargeting

use of com.android.bundle.Targeting.MultiAbiTargeting in project bundletool by google.

the class ApkMatcherTest method apexVariantMatch_matchesRightVariant.

@Test
public void apexVariantMatch_matchesRightVariant() {
    ZipPath x86Apk = ZipPath.create("standalone-x86.apk");
    ZipPath x64X86Apk = ZipPath.create("standalone-x86_64.x86.apk");
    ImmutableSet<ImmutableSet<AbiAlias>> x86Set = ImmutableSet.of(ImmutableSet.of(X86));
    ImmutableSet<ImmutableSet<AbiAlias>> x64X86Set = ImmutableSet.of(ImmutableSet.of(X86_64, X86));
    MultiAbiTargeting x86Targeting = multiAbiTargeting(x86Set, x64X86Set);
    MultiAbiTargeting x64X86Targeting = multiAbiTargeting(x64X86Set, x86Set);
    BuildApksResult buildApksResult = BuildApksResult.newBuilder().addVariant(multiAbiTargetingApexVariant(x86Targeting, x86Apk)).addVariant(multiAbiTargetingApexVariant(x64X86Targeting, x64X86Apk)).setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).build();
    assertThat(new ApkMatcher(abis("x86")).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(x86Apk));
    assertThat(new ApkMatcher(abis("x86_64", "x86")).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(x64X86Apk));
    assertThat(new ApkMatcher(abis("x86_64", "x86", "armeabi-v7a")).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(x64X86Apk));
    // Other device specs don't affect the matching variant.
    assertThat(new ApkMatcher(deviceWith(26, ImmutableList.of("x86"), HDPI)).getMatchingApks(buildApksResult)).containsExactly(baseMatchedApk(x86Apk));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) MultiAbiTargeting(com.android.bundle.Targeting.MultiAbiTargeting) Test(org.junit.Test)

Example 2 with MultiAbiTargeting

use of com.android.bundle.Targeting.MultiAbiTargeting in project bundletool by google.

the class VariantMatcherTest method getAllMatchingVariants_apexVariants_noMatch_throws.

@Test
public void getAllMatchingVariants_apexVariants_noMatch_throws() {
    ZipPath x86Apk = ZipPath.create("standalone-x86.apk");
    ZipPath x64X86Apk = ZipPath.create("standalone-x86_64.x86.apk");
    ImmutableSet<ImmutableSet<AbiAlias>> x86Set = ImmutableSet.of(ImmutableSet.of(X86));
    ImmutableSet<ImmutableSet<AbiAlias>> x64X86Set = ImmutableSet.of(ImmutableSet.of(X86_64, X86));
    MultiAbiTargeting x86Targeting = multiAbiTargeting(x86Set, x64X86Set);
    MultiAbiTargeting x64X86Targeting = multiAbiTargeting(x64X86Set, x86Set);
    Variant x86Variant = multiAbiTargetingApexVariant(x86Targeting, x86Apk);
    Variant x64X86Variant = multiAbiTargetingApexVariant(x64X86Targeting, x64X86Apk);
    BuildApksResult buildApksResult = BuildApksResult.newBuilder().addAllVariant(ImmutableList.of(x86Variant, x64X86Variant)).build();
    IncompatibleDeviceException e = assertThrows(IncompatibleDeviceException.class, () -> new VariantMatcher(abis("x86_64", "armeabi-v7a")).getAllMatchingVariants(buildApksResult));
    assertThat(e).hasMessageThat().contains("No set of ABI architectures that the app supports is contained in the ABI " + "architecture set of the device");
}
Also used : ApksArchiveHelpers.createVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant) Variant(com.android.bundle.Commands.Variant) ApksArchiveHelpers.multiAbiTargetingApexVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.multiAbiTargetingApexVariant) ApksArchiveHelpers.standaloneVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant) ImmutableSet(com.google.common.collect.ImmutableSet) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) IncompatibleDeviceException(com.android.tools.build.bundletool.model.exceptions.IncompatibleDeviceException) MultiAbiTargeting(com.android.bundle.Targeting.MultiAbiTargeting) Test(org.junit.Test)

Example 3 with MultiAbiTargeting

use of com.android.bundle.Targeting.MultiAbiTargeting in project bundletool by google.

the class VariantMatcherTest method getAllMatchingVariants_apexVariants_fullDeviceSpec.

@Test
public void getAllMatchingVariants_apexVariants_fullDeviceSpec() {
    ZipPath x86Apk = ZipPath.create("standalone-x86.apk");
    ZipPath x64X86Apk = ZipPath.create("standalone-x86_64.x86.apk");
    ImmutableSet<ImmutableSet<AbiAlias>> x86Set = ImmutableSet.of(ImmutableSet.of(X86));
    ImmutableSet<ImmutableSet<AbiAlias>> x64X86Set = ImmutableSet.of(ImmutableSet.of(X86_64, X86));
    MultiAbiTargeting x86Targeting = multiAbiTargeting(x86Set, x64X86Set);
    MultiAbiTargeting x64X86Targeting = multiAbiTargeting(x64X86Set, x86Set);
    Variant x86Variant = multiAbiTargetingApexVariant(x86Targeting, x86Apk);
    Variant x64X86Variant = multiAbiTargetingApexVariant(x64X86Targeting, x64X86Apk);
    BuildApksResult buildApksResult = BuildApksResult.newBuilder().addAllVariant(ImmutableList.of(x86Variant, x64X86Variant)).build();
    assertThat(new VariantMatcher(abis("x86")).getAllMatchingVariants(buildApksResult)).containsExactly(x86Variant);
    assertThat(new VariantMatcher(abis("x86_64", "x86")).getAllMatchingVariants(buildApksResult)).containsExactly(x64X86Variant);
    assertThat(new VariantMatcher(abis("x86_64", "x86", "armeabi-v7a")).getAllMatchingVariants(buildApksResult)).containsExactly(x64X86Variant);
    // Other device specs don't affect the matching variant.
    assertThat(new VariantMatcher(mergeSpecs(abis("x86"), density(HDPI))).getAllMatchingVariants(buildApksResult)).containsExactly(x86Variant);
}
Also used : ApksArchiveHelpers.createVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant) Variant(com.android.bundle.Commands.Variant) ApksArchiveHelpers.multiAbiTargetingApexVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.multiAbiTargetingApexVariant) ApksArchiveHelpers.standaloneVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant) ImmutableSet(com.google.common.collect.ImmutableSet) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) MultiAbiTargeting(com.android.bundle.Targeting.MultiAbiTargeting) Test(org.junit.Test)

Example 4 with MultiAbiTargeting

use of com.android.bundle.Targeting.MultiAbiTargeting in project bundletool by google.

the class ModuleSplit method getSuffix.

/**
 * Returns the split suffix base name based on the targeting.
 *
 * <p>The split suffix cannot contain dashes as they are not allowed by the Android Framework. We
 * replace them with underscores instead.
 */
public String getSuffix() {
    if (isMasterSplit()) {
        return "";
    }
    StringJoiner suffixJoiner = new StringJoiner("_");
    // The dimensions below should be ordered by their priority.
    AbiTargeting abiTargeting = getApkTargeting().getAbiTargeting();
    if (!abiTargeting.getValueList().isEmpty()) {
        abiTargeting.getValueList().forEach(value -> suffixJoiner.add(formatAbi(value)));
    } else if (!abiTargeting.getAlternativesList().isEmpty()) {
        suffixJoiner.add("other_abis");
    }
    MultiAbiTargeting multiAbiTargeting = getApkTargeting().getMultiAbiTargeting();
    for (MultiAbi value : multiAbiTargeting.getValueList()) {
        suffixJoiner.add(MULTI_ABI_SUFFIX_JOINER.join(value.getAbiList().stream().map(ModuleSplit::formatAbi).collect(toImmutableList())));
    }
    // Alternatives without values are not supported for MultiAbiTargeting.
    SanitizerTargeting sanitizerTargeting = getApkTargeting().getSanitizerTargeting();
    for (Sanitizer sanitizer : sanitizerTargeting.getValueList()) {
        if (sanitizer.getAlias().equals(SanitizerAlias.HWADDRESS)) {
            suffixJoiner.add("hwasan");
        } else {
            throw new IllegalArgumentException("Unknown sanitizer");
        }
    }
    LanguageTargeting languageTargeting = getApkTargeting().getLanguageTargeting();
    if (!languageTargeting.getValueList().isEmpty()) {
        languageTargeting.getValueList().forEach(suffixJoiner::add);
    } else if (!languageTargeting.getAlternativesList().isEmpty()) {
        suffixJoiner.add("other_lang");
    }
    getApkTargeting().getScreenDensityTargeting().getValueList().forEach(value -> suffixJoiner.add(SCREEN_DENSITY_TO_PROTO_VALUE_MAP.inverse().get(value.getDensityAlias()).replace('-', '_')));
    TextureCompressionFormatTargeting textureFormatTargeting = getApkTargeting().getTextureCompressionFormatTargeting();
    if (!textureFormatTargeting.getValueList().isEmpty()) {
        textureFormatTargeting.getValueList().forEach(value -> suffixJoiner.add(Ascii.toLowerCase(value.getAlias().name())));
    } else if (!textureFormatTargeting.getAlternativesList().isEmpty()) {
        suffixJoiner.add("other_tcf");
    }
    getApkTargeting().getDeviceTierTargeting().getValueList().forEach(value -> suffixJoiner.add("tier_" + value.getValue()));
    return suffixJoiner.toString();
}
Also used : LanguageTargeting(com.android.bundle.Targeting.LanguageTargeting) MultiAbiTargeting(com.android.bundle.Targeting.MultiAbiTargeting) AbiTargeting(com.android.bundle.Targeting.AbiTargeting) TextureCompressionFormatTargeting(com.android.bundle.Targeting.TextureCompressionFormatTargeting) SanitizerTargeting(com.android.bundle.Targeting.SanitizerTargeting) Sanitizer(com.android.bundle.Targeting.Sanitizer) MultiAbi(com.android.bundle.Targeting.MultiAbi) StringJoiner(java.util.StringJoiner) MultiAbiTargeting(com.android.bundle.Targeting.MultiAbiTargeting)

Example 5 with MultiAbiTargeting

use of com.android.bundle.Targeting.MultiAbiTargeting in project bundletool by google.

the class ExtractApksCommandTest method apexModule_getsBestPossibleApk.

@Test
@Theory
public void apexModule_getsBestPossibleApk(@FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception {
    ZipPath x64Apk = ZipPath.create("standalones/standalone-x86_64.apk");
    ZipPath x64X86Apk = ZipPath.create("standalones/standalone-x86_64.x86.apk");
    ZipPath x64ArmApk = ZipPath.create("standalones/standalone-x86_64.arm64_v8a.apk");
    MultiAbiTargeting x64Targeting = multiAbiTargeting(ImmutableSet.of(ImmutableSet.of(X86_64)), ImmutableSet.of(ImmutableSet.of(X86_64, X86), ImmutableSet.of(X86_64, ARM64_V8A)));
    MultiAbiTargeting x64X86Targeting = multiAbiTargeting(ImmutableSet.of(ImmutableSet.of(X86_64, X86)), ImmutableSet.of(ImmutableSet.of(X86_64), ImmutableSet.of(X86_64, ARM64_V8A)));
    MultiAbiTargeting x64ArmTargeting = multiAbiTargeting(ImmutableSet.of(ImmutableSet.of(X86_64, ARM64_V8A)), ImmutableSet.of(ImmutableSet.of(X86_64), ImmutableSet.of(X86_64, X86)));
    BuildApksResult buildApksResult = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(multiAbiTargetingApexVariant(x64Targeting, x64Apk)).addVariant(multiAbiTargetingApexVariant(x64X86Targeting, x64X86Apk)).addVariant(multiAbiTargetingApexVariant(x64ArmTargeting, x64ArmApk)).build();
    Path apksPath = createApks(buildApksResult, apksInDirectory);
    ExtractApksCommand.Builder extractedApksCommand = ExtractApksCommand.builder().setApksArchivePath(apksPath).setDeviceSpec(abis("x86_64", "x86"));
    if (!apksInDirectory) {
        extractedApksCommand.setOutputDirectory(tmpDir);
    }
    ImmutableList<Path> matchedApks = extractedApksCommand.build().execute();
    if (apksInDirectory) {
        assertThat(matchedApks).containsExactly(inTempDirectory(x64X86Apk.toString()));
    } else {
        assertThat(matchedApks).containsExactly(inOutputDirectory(x64X86Apk.getFileName()));
    }
    for (Path matchedApk : matchedApks) {
        checkFileExistsAndReadable(tmpDir.resolve(matchedApk));
    }
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ZipPath(com.android.tools.build.bundletool.model.ZipPath) MultiAbiTargeting(com.android.bundle.Targeting.MultiAbiTargeting) Test(org.junit.Test) Theory(org.junit.experimental.theories.Theory)

Aggregations

MultiAbiTargeting (com.android.bundle.Targeting.MultiAbiTargeting)6 BuildApksResult (com.android.bundle.Commands.BuildApksResult)5 ZipPath (com.android.tools.build.bundletool.model.ZipPath)5 Test (org.junit.Test)5 ImmutableSet (com.google.common.collect.ImmutableSet)4 Variant (com.android.bundle.Commands.Variant)2 IncompatibleDeviceException (com.android.tools.build.bundletool.model.exceptions.IncompatibleDeviceException)2 ApksArchiveHelpers.createVariant (com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant)2 ApksArchiveHelpers.multiAbiTargetingApexVariant (com.android.tools.build.bundletool.testing.ApksArchiveHelpers.multiAbiTargetingApexVariant)2 ApksArchiveHelpers.standaloneVariant (com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant)2 AbiTargeting (com.android.bundle.Targeting.AbiTargeting)1 LanguageTargeting (com.android.bundle.Targeting.LanguageTargeting)1 MultiAbi (com.android.bundle.Targeting.MultiAbi)1 Sanitizer (com.android.bundle.Targeting.Sanitizer)1 SanitizerTargeting (com.android.bundle.Targeting.SanitizerTargeting)1 TextureCompressionFormatTargeting (com.android.bundle.Targeting.TextureCompressionFormatTargeting)1 Path (java.nio.file.Path)1 StringJoiner (java.util.StringJoiner)1 Theory (org.junit.experimental.theories.Theory)1