use of com.android.bundle.Commands.Variant 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.Commands.Variant in project bundletool by google.
the class BuildApksManagerTest method pinningOfManifestReachableResources_enabledSince_0_8_1.
@Test
public void pinningOfManifestReachableResources_enabledSince_0_8_1() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("res/drawable-mdpi/manifest_image.jpg").addFile("res/drawable-hdpi/manifest_image.jpg").addFile("res/drawable-mdpi/other_image.jpg").addFile("res/drawable-hdpi/other_image.jpg").setManifest(androidManifest("com.test.app", withAppIcon(/* ID of "drawable/manifest_image" */
0x7f010000))).setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("manifest_image", ImmutableMap.of(/* mdpi */
160, "res/drawable-mdpi/manifest_image.jpg", /* hdpi */
240, "res/drawable-hdpi/manifest_image.jpg")).addDrawableResourceForMultipleDensities("other_image", ImmutableMap.of(/* mdpi */
160, "res/drawable-mdpi/other_image.jpg", /* hdpi */
240, "res/drawable-hdpi/other_image.jpg")).build())).setBundleConfig(BundleConfigBuilder.create().setVersion("0.8.1").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);
ImmutableList<ApkDescription> splitApks = apkDescriptions(splitApkVariants);
// The lowest density (mdpi) of "drawable/manifest_reachable_image" is in the master.
ImmutableList<ApkDescription> masterSplits = splitApks.stream().filter(apkDesc -> apkDesc.getSplitApkMetadata().getIsMasterSplit()).collect(toImmutableList());
assertThat(masterSplits).isNotEmpty();
for (ApkDescription masterSplit : masterSplits) {
assertThat(filesInApk(masterSplit, apkSetFile)).contains("res/drawable-mdpi/manifest_image.jpg");
}
ImmutableList<ApkDescription> densitySplits = splitApks.stream().filter(apkDesc -> apkDesc.getTargeting().hasScreenDensityTargeting()).collect(toImmutableList());
assertThat(densitySplits).isNotEmpty();
for (ApkDescription densitySplit : densitySplits) {
assertThat(filesInApk(densitySplit, apkSetFile)).doesNotContain("res/drawable-mdpi/manifest_image.jpg");
}
}
use of com.android.bundle.Commands.Variant in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_appTargetingLPlus_buildsSplitApksOnly.
@Test
public void buildApksCommand_appTargetingLPlus_buildsSplitApksOnly() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.test.app", withMinSdkVersion(ANDROID_L_API_VERSION)))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(result.getVariantList()).hasSize(1);
assertThat(standaloneApkVariants(result)).isEmpty();
assertThat(splitApkVariants(result)).hasSize(1);
Variant splitApksVariant = splitApkVariants(result).get(0);
assertThat(splitApksVariant.getTargeting()).isEqualTo(variantSdkTargeting(L_SDK_VERSION));
}
use of com.android.bundle.Commands.Variant in project bundletool by google.
the class BuildSdkApksManagerTest method manifestIsMutated.
@Test
public void manifestIsMutated() throws Exception {
Integer versionCode = 1253;
execute(new SdkBundleBuilder().setVersionCode(versionCode).build());
ZipFile apkSetFile = new ZipFile(outputFilePath.toFile());
BuildSdkApksResult result = extractTocFromSdkApkSetFile(apkSetFile, tmpDir);
Variant variant = result.getVariant(0);
ApkDescription apkDescription = variant.getApkSet(0).getApkDescription(0);
File apkFile = extractFromApkSetFile(apkSetFile, apkDescription.getPath(), tmpDir);
AndroidManifest manifest = extractAndroidManifest(apkFile, tmpDir);
assertThat(manifest.getMinSdkVersion()).hasValue(SDK_SANDBOX_MIN_VERSION);
assertThat(manifest.getManifestRoot().getElement().getAndroidAttribute(VERSION_NAME_RESOURCE_ID).get().getValueAsString()).isEqualTo("15.0.5");
assertThat(manifest.getManifestRoot().getElement().getAndroidAttribute(VERSION_CODE_RESOURCE_ID).get().getValueAsDecimalInteger()).isEqualTo(versionCode);
}
use of com.android.bundle.Commands.Variant in project bundletool by google.
the class BuildSdkApksManagerTest method apksSigned.
@Test
public void apksSigned() throws Exception {
execute(new SdkBundleBuilder().build());
ZipFile apkSetFile = new ZipFile(outputFilePath.toFile());
BuildSdkApksResult result = extractTocFromSdkApkSetFile(apkSetFile, tmpDir);
Variant variant = result.getVariant(0);
ApkDescription apkDescription = variant.getApkSet(0).getApkDescription(0);
File apkFile = extractFromApkSetFile(apkSetFile, apkDescription.getPath(), tmpDir);
ApkVerifier.Result verifierResult = new ApkVerifier.Builder(apkFile).build().verify();
assertThat(verifierResult.isVerified()).isTrue();
assertThat(verifierResult.getSignerCertificates()).containsExactly(certificate);
}
Aggregations