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));
}
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");
}
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);
}
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();
}
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));
}
}
Aggregations