use of com.android.bundle.Targeting.Abi.AbiAlias 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");
}
use of com.android.bundle.Targeting.Abi.AbiAlias in project bundletool by google.
the class AbiMatcher method matchesTargeting.
@Override
public boolean matchesTargeting(AbiTargeting targeting) {
// Test if the targeting has anything specific for ABI.
if (targeting.equals(AbiTargeting.getDefaultInstance())) {
return true;
}
ImmutableSet<AbiAlias> valuesList = targeting.getValueList().stream().map(Abi::getAlias).collect(toImmutableSet());
ImmutableSet<AbiAlias> alternativesList = targeting.getAlternativesList().stream().map(Abi::getAlias).collect(toImmutableSet());
SetView<AbiAlias> intersection = Sets.intersection(valuesList, alternativesList);
checkArgument(intersection.isEmpty(), "Expected targeting values and alternatives to be mutually exclusive, but both contain: %s", intersection);
// If we find it in alternatives first, it means there is a better match.
for (String abi : getDeviceSpec().getSupportedAbisList()) {
AbiAlias abiAlias = AbiName.fromPlatformName(abi).orElseThrow(() -> IncompatibleDeviceException.builder().withUserMessage("Unrecognized ABI '%s' in device spec.", abi).build()).toProto();
if (valuesList.contains(abiAlias)) {
return true;
}
if (alternativesList.contains(abiAlias)) {
return false;
}
}
return valuesList.isEmpty();
}
use of com.android.bundle.Targeting.Abi.AbiAlias in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_apkNotificationMessageKeyApexBundle_previewTargetSdk.
@Test
public void buildApksCommand_apkNotificationMessageKeyApexBundle_previewTargetSdk() throws Exception {
ApexImages apexConfig = apexImages(targetedApexImage("apex/x86_64.img", apexImageTargeting("x86_64")), targetedApexImage("apex/x86.img", apexImageTargeting("x86")), targetedApexImage("apex/arm64-v8a.img", apexImageTargeting("arm64-v8a")), targetedApexImage("apex/armeabi-v7a.img", apexImageTargeting("armeabi-v7a")));
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile(APEX_MANIFEST_PATH, APEX_MANIFEST).addFile("apex/x86_64.img").addFile("apex/x86.img").addFile("apex/arm64-v8a.img").addFile("apex/armeabi-v7a.img").setApexConfig(apexConfig).setManifest(androidManifest("com.test.app", withTargetSdkVersion("Q.fingerprint"), withMinSdkVersion("Q.fingerprint")))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ImmutableSet<AbiAlias> x64Set = ImmutableSet.of(X86_64);
ImmutableSet<AbiAlias> x86Set = ImmutableSet.of(X86);
ImmutableSet<AbiAlias> arm8Set = ImmutableSet.of(ARM64_V8A);
ImmutableSet<AbiAlias> arm7Set = ImmutableSet.of(ARMEABI_V7A);
ImmutableSet<ImmutableSet<AbiAlias>> allTargeting = ImmutableSet.of(arm7Set, arm8Set, x86Set, x64Set);
ApkTargeting x64Targeting = apkMultiAbiTargetingFromAllTargeting(x64Set, allTargeting);
ApkTargeting x86Targeting = apkMultiAbiTargetingFromAllTargeting(x86Set, allTargeting);
ApkTargeting arm8Targeting = apkMultiAbiTargetingFromAllTargeting(arm8Set, allTargeting);
ApkTargeting arm7Targeting = apkMultiAbiTargetingFromAllTargeting(arm7Set, allTargeting);
ZipFile apkSetFile = new ZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
ImmutableMap<ApkTargeting, Variant> apexVariantsByAbi = extractApexVariantsByTargeting(result);
assertThat(apexVariantsByAbi.keySet()).containsExactly(x64Targeting, x86Targeting, arm8Targeting, arm7Targeting);
assertThat(apexVariantsByAbi.values().stream().map(variant -> variant.getTargeting().getSdkVersionTargeting()).collect(toImmutableSet())).containsExactly(sdkVersionTargeting(sdkVersionFrom(DEVELOPMENT_SDK_VERSION), ImmutableSet.of()));
}
use of com.android.bundle.Targeting.Abi.AbiAlias in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_apkNotificationMessageKeyApexBundle.
@Test
public void buildApksCommand_apkNotificationMessageKeyApexBundle() 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/arm64-v8a.img", apexImageTargeting("arm64-v8a")), targetedApexImage("apex/armeabi-v7a.img", apexImageTargeting("armeabi-v7a")));
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile(APEX_MANIFEST_PATH, APEX_MANIFEST).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/arm64-v8a.img").addFile("apex/armeabi-v7a.img").setApexConfig(apexConfig).setManifest(androidManifest("com.test.app"))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
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> arm8Set = ImmutableSet.of(ARM64_V8A);
ImmutableSet<AbiAlias> arm7Set = ImmutableSet.of(ARMEABI_V7A);
ImmutableSet<ImmutableSet<AbiAlias>> allTargeting = ImmutableSet.of(arm7Set, x86ArmSet, x64ArmSet, arm8Set, x86Set, x64X86Set, x64Set);
ApkTargeting x64X86Targeting = apkMultiAbiTargetingFromAllTargeting(x64X86Set, allTargeting);
ApkTargeting x64ArmTargeting = apkMultiAbiTargetingFromAllTargeting(x64ArmSet, allTargeting);
ApkTargeting x64Targeting = apkMultiAbiTargetingFromAllTargeting(x64Set, allTargeting);
ApkTargeting x86ArmTargeting = apkMultiAbiTargetingFromAllTargeting(x86ArmSet, allTargeting);
ApkTargeting x86Targeting = apkMultiAbiTargetingFromAllTargeting(x86Set, allTargeting);
ApkTargeting arm8Targeting = apkMultiAbiTargetingFromAllTargeting(arm8Set, allTargeting);
ApkTargeting arm7Targeting = apkMultiAbiTargetingFromAllTargeting(arm7Set, allTargeting);
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
ImmutableMap<ApkTargeting, Variant> apexVariantsByAbi = extractApexVariantsByTargeting(result);
assertThat(apexVariantsByAbi.keySet()).containsExactly(x64X86Targeting, x64ArmTargeting, x64Targeting, x86ArmTargeting, x86Targeting, arm8Targeting, arm7Targeting);
checkVariantMultiAbiTargeting(apexVariantsByAbi.get(x64X86Targeting), variantMultiAbiTargetingFromAllTargeting(x64X86Set, allTargeting));
checkVariantMultiAbiTargeting(apexVariantsByAbi.get(x64ArmTargeting), variantMultiAbiTargetingFromAllTargeting(x64ArmSet, allTargeting));
checkVariantMultiAbiTargeting(apexVariantsByAbi.get(x64Targeting), variantMultiAbiTargetingFromAllTargeting(x64Set, allTargeting));
checkVariantMultiAbiTargeting(apexVariantsByAbi.get(x86ArmTargeting), variantMultiAbiTargetingFromAllTargeting(x86ArmSet, allTargeting));
checkVariantMultiAbiTargeting(apexVariantsByAbi.get(x86Targeting), variantMultiAbiTargetingFromAllTargeting(x86Set, allTargeting));
checkVariantMultiAbiTargeting(apexVariantsByAbi.get(arm8Targeting), variantMultiAbiTargetingFromAllTargeting(arm8Set, allTargeting));
checkVariantMultiAbiTargeting(apexVariantsByAbi.get(arm7Targeting), variantMultiAbiTargetingFromAllTargeting(arm7Set, allTargeting));
for (Variant variant : apexVariantsByAbi.values()) {
ApkSet apkSet = getOnlyElement(variant.getApkSetList());
ApkDescription apkDescription = getOnlyElement(apkSet.getApkDescriptionList());
assertThat(apkSetFile).hasFile(apkDescription.getPath());
}
}
Aggregations