use of com.android.bundle.Commands.BuildApksResult in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_system_generatesSingleApkWithEmptyOptimizations.
@Test
public void buildApksCommand_system_generatesSingleApkWithEmptyOptimizations() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", 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)))).addFile("res/drawable-ldpi/image.jpg").addFile("res/drawable-mdpi/image.jpg").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addFileResourceForMultipleConfigs("drawable", "image", ImmutableMap.of(LDPI, "res/drawable-ldpi/image.jpg", MDPI, "res/drawable-mdpi/image.jpg")).build()).setManifest(androidManifest("com.test.app"))).setBundleConfig(BundleConfigBuilder.create().addSplitDimension(Value.ABI, /* negate= */
true).addSplitDimension(Value.SCREEN_DENSITY, /* negate= */
true).build()).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withApkBuildMode(SYSTEM).withDeviceSpec(mergeSpecs(sdkVersion(28), abis("x86"), density(DensityAlias.MDPI), locales("en-US"))).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
// Should not shard by any dimension and generate single APK with default targeting.
assertThat(result.getVariantList()).hasSize(1);
assertThat(splitApkVariants(result)).isEmpty();
assertThat(standaloneApkVariants(result)).isEmpty();
assertThat(systemApkVariants(result)).hasSize(1);
Variant systemVariant = systemApkVariants(result).get(0);
assertThat(systemVariant.getTargeting()).isEqualTo(UNRESTRICTED_VARIANT_TARGETING);
assertThat(apkDescriptions(systemVariant)).hasSize(1);
ApkDescription systemApk = apkDescriptions(systemVariant).get(0);
assertThat(systemApk.getTargeting()).isEqualToDefaultInstance();
File systemApkFile = extractFromApkSetFile(apkSetFile, systemApk.getPath(), outputDir);
try (ZipFile systemApkZipFile = new ZipFile(systemApkFile)) {
// "res/xml/splits0.xml" is created by bundletool with list of generated splits.
TruthZip.assertThat(systemApkZipFile).containsExactlyEntries("AndroidManifest.xml", "lib/x86/libsome.so", "lib/x86_64/libsome.so", "res/drawable-ldpi/image.jpg", "res/drawable-mdpi/image.jpg", "res/xml/splits0.xml", "resources.arsc");
}
}
use of com.android.bundle.Commands.BuildApksResult in project bundletool by google.
the class BuildApksManagerTest method apkWithSourceStamp.
@Test
public void apkWithSourceStamp() throws Exception {
String stampSource = "https://www.example.com";
SigningConfiguration signingConfiguration = SigningConfiguration.builder().setSignerConfig(privateKey, certificate).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withOutputPath(outputFilePath).withSigningConfig(signingConfiguration).withSourceStamp(SourceStamp.builder().setSource(stampSource).setSigningConfiguration(signingConfiguration).build()).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
for (Variant variant : result.getVariantList()) {
for (ApkSet apkSet : variant.getApkSetList()) {
for (ApkDescription apkDescription : apkSet.getApkDescriptionList()) {
File apk = extractFromApkSetFile(apkSetFile, apkDescription.getPath(), outputDir);
ApkVerifier.Result verifierResult = new ApkVerifier.Builder(apk).build().verify();
assertThat(verifierResult.isSourceStampVerified()).isTrue();
assertThat(verifierResult.getSourceStampInfo().getCertificate()).isEqualTo(certificate);
AndroidManifest manifest = extractAndroidManifest(apk, tmpDir);
assertThat(manifest.getMetadataValue(STAMP_SOURCE_METADATA_KEY)).hasValue(stampSource);
try (ZipFile apkZip = new ZipFile(apk)) {
ZipEntry sourceStampCertEntry = apkZip.getEntry("stamp-cert-sha256");
assertNotNull(sourceStampCertEntry);
byte[] sourceStampCertHash = ByteStreams.toByteArray(apkZip.getInputStream(sourceStampCertEntry));
assertThat(sourceStampCertHash).isEqualTo(CertificateHelper.getSha256Bytes(certificate.getEncoded()));
}
}
}
}
}
use of com.android.bundle.Commands.BuildApksResult in project bundletool by google.
the class BuildApksManagerTest method splits_assetMixedTextureCompressionFormat.
@Test
public void splits_assetMixedTextureCompressionFormat() throws Exception {
// Create a bundle with assets containing both ETC1 textures and textures without
// targeting specified.
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("assets/textures/untargeted_texture.dat").addFile("assets/textures#tcf_etc1/etc1_texture.dat").setManifest(androidManifest("com.test.app")).setAssetsConfig(assets(targetedAssetsDirectory("assets/textures", assetsDirectoryTargeting(alternativeTextureCompressionTargeting(ETC1_RGB8))), targetedAssetsDirectory("assets/textures#tcf_etc1", assetsDirectoryTargeting(textureCompressionTargeting(ETC1_RGB8)))))).setBundleConfig(BundleConfigBuilder.create().addSplitDimension(Value.TEXTURE_COMPRESSION_FORMAT, /* negate= */
false).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);
assertThat(splitApkVariants(result)).hasSize(1);
Variant splitApkVariant = splitApkVariants(result).get(0);
// Check that apks for ETC1 and "Other TCF" have been created
assertThat(splitApkVariant.getApkSetList()).hasSize(1);
ImmutableList<ApkDescription> tcfSplits = splitApks.stream().filter(apkDesc -> apkDesc.getTargeting().hasTextureCompressionFormatTargeting()).collect(toImmutableList());
assertThat(apkNamesInApkDescriptions(tcfSplits)).containsExactly("base-other_tcf.apk", "base-etc1_rgb8.apk");
// Check the content of the apks
for (ApkDescription split : tcfSplits) {
TextureCompressionFormatTargeting textureFormatTargeting = split.getTargeting().getTextureCompressionFormatTargeting();
Set<String> files = filesInApk(split, apkSetFile);
if (textureFormatTargeting.getValueList().isEmpty()) {
// The "Other TCF" split contains the untargeted texture only.
assertThat(files).contains("assets/textures/untargeted_texture.dat");
} else {
// The "ETC1" split contains the ETC1 texture only.
TextureCompressionFormat format = textureFormatTargeting.getValueList().get(0);
assertThat(format.getAlias()).isEqualTo(ETC1_RGB8);
assertThat(files).contains("assets/textures#tcf_etc1/etc1_texture.dat");
}
}
}
use of com.android.bundle.Commands.BuildApksResult in project bundletool by google.
the class BuildApksManagerTest method packageNameIsPropagatedToBuildResult.
@Test
public void packageNameIsPropagatedToBuildResult() throws Exception {
TestComponent.useTestModule(this, createTestModuleBuilder().withOutputPath(outputFilePath).withAppBundle(new AppBundleBuilder().addModule("base", module -> module.setManifest(androidManifest("com.app"))).build()).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(result.getPackageName()).isEqualTo("com.app");
}
use of com.android.bundle.Commands.BuildApksResult in project bundletool by google.
the class BuildApksManagerTest method extractApkSet_outputApksWithoutArchive.
@Test
public void extractApkSet_outputApksWithoutArchive() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("assets/file.txt").addFile("dex/classes.dex").setManifest(androidManifest("com.test.app")).setResourceTable(resourceTableWithTestLabel("test_label"))).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(androidManifestForFeature("com.test.app", withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).addModule("language_feature", builder -> builder.addFile("res/drawable/image.jpg").addFile("res/drawable-cz/image.jpg").addFile("res/drawable-fr/image.jpg").addFile("res/drawable-pl/image.jpg").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app", USER_PACKAGE_OFFSET - 1).addFileResourceForMultipleConfigs("drawable", "image", ImmutableMap.of(Configuration.getDefaultInstance(), "res/drawable/image.jpg", locale("cz"), "res/drawable-cz/image.jpg", locale("fr"), "res/drawable-fr/image.jpg", locale("pl"), "res/drawable-pl/image.jpg")).build()).setManifest(androidManifestForFeature("com.test.app", withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputDir).withOptimizationDimensions(ABI, LANGUAGE).withCustomBuildApksCommandSetter(command -> command.setOutputFormat(DIRECTORY)).build());
buildApksManager.execute();
assertThat(command.getOutputFile()).isEqualTo(outputDir);
BuildApksResult result = parseTocFromFile(outputDir.resolve("toc.pb").toFile());
// Validate all APKs were created.
verifyApksExist(apkDescriptions(result.getVariantList()), outputDir);
}
Aggregations