use of com.android.bundle.Targeting.Abi.AbiAlias.X86_64 in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_apkNotificationMessageKeyApexBundle_hasRightSuffix.
@Test
public void buildApksCommand_apkNotificationMessageKeyApexBundle_hasRightSuffix() 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")), targetedApexImage("apex/arm64-v8a.armeabi-v7a.img", apexImageTargeting("arm64-v8a", "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").addFile("apex/arm64-v8a.armeabi-v7a.img").setApexConfig(apexConfig).setManifest(androidManifest("com.test.app"))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
BuildApksResult result = extractTocFromApkSetFile(openZipFile(outputFilePath.toFile()), outputDir);
ImmutableList<Variant> variants = apexApkVariants(result);
ImmutableSet<String> apkPaths = variants.stream().map(variant -> getOnlyElement(getOnlyElement(variant.getApkSetList()).getApkDescriptionList()).getPath()).collect(toImmutableSet());
assertThat(apkPaths).containsExactly("standalones/standalone-x86_64.apex", "standalones/standalone-x86.apex", "standalones/standalone-arm64_v8a.apex", "standalones/standalone-armeabi_v7a.apex", "standalones/standalone-armeabi_v7a.arm64_v8a.apex");
}
use of com.android.bundle.Targeting.Abi.AbiAlias.X86_64 in project bundletool by google.
the class BuildApksManagerTest method transparencyFilePropagatedAsExpected.
@Test
public void transparencyFilePropagatedAsExpected() throws Exception {
String dexFilePath = "dex/classes.dex";
byte[] dexFileInBaseModuleContent = TestData.readBytes("testdata/dex/classes.dex");
byte[] dexFileInFeatureModuleContent = TestData.readBytes("testdata/dex/classes-other.dex");
String libFilePath = "lib/x86_64/libsome.so";
byte[] libFileInBaseModuleContent = new byte[] { 4, 5, 6 };
CodeTransparency codeTransparency = CodeTransparency.newBuilder().addCodeRelatedFile(CodeRelatedFile.newBuilder().setType(CodeRelatedFile.Type.DEX).setPath("base/" + dexFilePath).setSha256(ByteSource.wrap(dexFileInBaseModuleContent).hash(Hashing.sha256()).toString())).addCodeRelatedFile(CodeRelatedFile.newBuilder().setType(CodeRelatedFile.Type.NATIVE_LIBRARY).setPath("base/" + libFilePath).setSha256(ByteSource.wrap(libFileInBaseModuleContent).hash(Hashing.sha256()).toString()).setApkPath(libFilePath)).addCodeRelatedFile(CodeRelatedFile.newBuilder().setType(CodeRelatedFile.Type.DEX).setPath("feature/" + dexFilePath).setSha256(ByteSource.wrap(dexFileInFeatureModuleContent).hash(Hashing.sha256()).toString())).build();
Path bundlePath = tmpDir.resolve("bundle.aab");
AppBundleBuilder appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(androidManifest("com.test.app", withMinSdkVersion(20))).setResourceTable(resourceTableWithTestLabel("Test feature")).addFile(dexFilePath, bundlePath, ZipPath.create("base/" + dexFilePath), dexFileInBaseModuleContent).addFile(libFilePath, bundlePath, ZipPath.create("base/" + libFilePath), libFileInBaseModuleContent).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(AbiAlias.X86_64))))).addModule("feature", module -> module.setManifest(androidManifest("com.test.app", withDelivery(DeliveryType.ON_DEMAND), withFusingAttribute(true), withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID))).addFile(dexFilePath, bundlePath, ZipPath.create("feature/" + dexFilePath), dexFileInFeatureModuleContent)).addMetadataFile(BundleMetadata.BUNDLETOOL_NAMESPACE, BundleMetadata.TRANSPARENCY_SIGNED_FILE_NAME, CharSource.wrap(createJwsToken(codeTransparency, certificate, privateKey)).asByteSource(Charset.defaultCharset()));
TestComponent.useTestModule(this, createTestModuleBuilder().withOutputPath(outputFilePath).withAppBundle(appBundle.build()).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
ImmutableList<ApkDescription> splitApks = apkDescriptions(splitApkVariants(result));
// Transparency file should be propagated to main split of the base module.
ImmutableList<ApkDescription> mainSplitsOfBaseModule = splitApks.stream().filter(apk -> apk.getSplitApkMetadata().getSplitId().isEmpty() && apk.getSplitApkMetadata().getIsMasterSplit()).collect(toImmutableList());
assertThat(mainSplitsOfBaseModule).hasSize(2);
for (ApkDescription apk : mainSplitsOfBaseModule) {
ZipFile zipFile = openZipFile(extractFromApkSetFile(apkSetFile, apk.getPath(), outputDir));
assertThat(filesUnderPath(zipFile, ZipPath.create("META-INF"))).contains("META-INF/" + BundleMetadata.TRANSPARENCY_SIGNED_FILE_NAME);
}
// Other splits should not contain transparency file.
ImmutableList<ApkDescription> otherSplits = splitApks.stream().filter(apk -> !apk.getSplitApkMetadata().getSplitId().isEmpty()).collect(toImmutableList());
assertThat(otherSplits).hasSize(4);
for (ApkDescription apk : otherSplits) {
ZipFile zipFile = openZipFile(extractFromApkSetFile(apkSetFile, apk.getPath(), outputDir));
assertThat(filesUnderPath(zipFile, ZipPath.create("META-INF"))).isEmpty();
}
// Because minSdkVersion < 21, bundle has a feature module and merging strategy is
// MERGE_IF_NEEDED (default), transparency file should not be propagated to standalone APK.
assertThat(standaloneApkVariants(result)).hasSize(1);
ImmutableList<ApkDescription> standaloneApks = apkDescriptions(standaloneApkVariants(result).get(0));
File standaloneApkFile = extractFromApkSetFile(apkSetFile, standaloneApks.get(0).getPath(), outputDir);
ZipFile standaloneApkZip = openZipFile(standaloneApkFile);
assertThat(filesUnderPath(standaloneApkZip, ZipPath.create("META-INF"))).isEmpty();
}
use of com.android.bundle.Targeting.Abi.AbiAlias.X86_64 in project bundletool by google.
the class SystemApksGeneratorTest method uncompressedNativeLibraries_enabled_multiApks.
@Test
public void uncompressedNativeLibraries_enabled_multiApks() throws Exception {
BundleModule baseModule = new BundleModuleBuilder("base").addFile("lib/x86_64/libtest1.so").addFile("lib/x86/libtest1.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)), targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)))).setManifest(androidManifestForFeature("com.test.app")).build();
BundleModule featureModule = new BundleModuleBuilder("feature").addFile("lib/x86_64/libtest2.so").addFile("lib/x86/libtest2.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)), targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)))).setManifest(androidManifestForFeature("com.test.app.feature")).build();
ApkOptimizations apkOptimizations = splitOptimizations(OptimizationDimension.ABI).toBuilder().setUncompressNativeLibraries(true).build();
ImmutableList<ModuleSplit> shards = systemApksGenerator.generateSystemApks(/* modules= */
ImmutableList.of(baseModule, featureModule), /* modulesToFuse= */
ImmutableSet.of(BASE_MODULE_NAME), apkOptimizations);
assertThat(shards).hasSize(3);
ModuleSplit systemApk = getSystemImageSplit(shards);
assertThat(systemApk.getAndroidManifest().getExtractNativeLibsValue()).hasValue(false);
assertThat(systemApk.findEntry("lib/x86/libtest1.so").map(ModuleEntry::getForceUncompressed)).hasValue(true);
ModuleSplit additionalNativeSplit = getAdditionalSplits(shards).stream().filter(split -> split.getApkTargeting().hasAbiTargeting()).collect(onlyElement());
assertThat(additionalNativeSplit.findEntry("lib/x86/libtest2.so").map(ModuleEntry::getForceUncompressed)).hasValue(true);
}
use of com.android.bundle.Targeting.Abi.AbiAlias.X86_64 in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_standalone_oneModuleManyVariants.
@Test
public void buildApksCommand_standalone_oneModuleManyVariants() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("dex/classes.dex").addFile("lib/x86/libsome.so").addFile("lib/x86_64/libsome.so").addFile("lib/mips/libsome.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)), targetedNativeDirectory("lib/mips", nativeDirectoryTargeting(MIPS)))).setManifest(androidManifest("com.test.app"))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withOptimizationDimensions(ABI).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
ImmutableMap<Abi, Variant> standaloneVariantsByAbi = Maps.uniqueIndex(standaloneApkVariants(result), variant -> {
ApkDescription apkDescription = getOnlyElement(apkDescriptions(variant));
return getOnlyElement(apkDescription.getTargeting().getAbiTargeting().getValueList());
});
assertThat(standaloneVariantsByAbi.keySet()).containsExactly(toAbi(X86), toAbi(X86_64), toAbi(MIPS));
assertThat(standaloneVariantsByAbi.get(toAbi(X86)).getTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeVariantTargeting(variantAbiTargeting(X86, ImmutableSet.of(X86_64, MIPS)), variantSdkTargeting(LOWEST_SDK_VERSION, ImmutableSet.of(L_SDK_VERSION, M_SDK_VERSION))));
assertThat(standaloneVariantsByAbi.get(toAbi(X86_64)).getTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeVariantTargeting(variantAbiTargeting(X86_64, ImmutableSet.of(X86, MIPS)), variantSdkTargeting(LOWEST_SDK_VERSION, ImmutableSet.of(L_SDK_VERSION, M_SDK_VERSION))));
assertThat(standaloneVariantsByAbi.get(toAbi(MIPS)).getTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeVariantTargeting(variantAbiTargeting(MIPS, ImmutableSet.of(X86, X86_64)), variantSdkTargeting(LOWEST_SDK_VERSION, ImmutableSet.of(L_SDK_VERSION, M_SDK_VERSION))));
for (Variant variant : standaloneVariantsByAbi.values()) {
assertThat(variant.getApkSetList()).hasSize(1);
ApkSet apkSet = variant.getApkSet(0);
assertThat(apkSet.getApkDescriptionList()).hasSize(1);
assertThat(apkSetFile).hasFile(apkSet.getApkDescription(0).getPath());
}
}
use of com.android.bundle.Targeting.Abi.AbiAlias.X86_64 in project bundletool by google.
the class BuildApksManagerTest method mergeInstallTimeModulesByDefault.
@Test
public void mergeInstallTimeModulesByDefault() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("dex/classes.dex").setManifest(androidManifest("com.test.app"))).addModule("abi_feature", builder -> builder.addFile("lib/x86/libsome.so").addFile("lib/x86_64/libsome.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)))).setManifest(androidManifest("com.test.app", withInstallTimeDelivery(), withFusingAttribute(true)))).setBundleConfig(BundleConfigBuilder.create().setVersion("1.0.0").build()).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
ImmutableList<Variant> splitApkVariants = splitApkVariants(result);
assertThat(splitApkVariants).isNotEmpty();
assertThat(result.getPermanentlyFusedModulesList()).containsExactly(PermanentlyFusedModule.newBuilder().setName("abi_feature").build());
for (Variant splitApkVariant : splitApkVariants(result)) {
assertThat(splitApkVariant.getApkSetList()).comparingElementsUsing(Correspondence.from((ApkSet apkSet, String moduleName) -> apkSet != null && apkSet.getModuleMetadata().getName().equals(moduleName), "equals")).containsExactly("base");
}
}
Aggregations