use of com.android.bundle.Commands.ApkDescription 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.ApkDescription 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.Commands.ApkDescription 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.ApkDescription 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);
}
use of com.android.bundle.Commands.ApkDescription in project bundletool by google.
the class BuildSdkApksManagerTest method sdkManifestMutation_highMinSdkVersion_minSdkVersionUnchanged.
@Test
public void sdkManifestMutation_highMinSdkVersion_minSdkVersionUnchanged() throws Exception {
SdkBundle sdkBundle = new SdkBundleBuilder().setModule(new BundleModuleBuilder("base").setManifest(androidManifest(PACKAGE_NAME, withMinSdkVersion(SDK_SANDBOX_MIN_VERSION + 5), withSdkLibraryElement("20"), withMetadataValue(SDK_PATCH_VERSION_ATTRIBUTE_NAME, "12"))).build()).build();
execute(sdkBundle);
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 + 5);
}
Aggregations