use of com.android.bundle.Commands.ApkDescription in project bundletool by google.
the class BuildApksManagerTest method allApksNotSignedWithV1_minSdkAtLeast24_recentBundletool.
@Test
public void allApksNotSignedWithV1_minSdkAtLeast24_recentBundletool() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.app", withMinSdkVersion(24)))).setBundleConfig(BundleConfig.newBuilder().setBundletool(Bundletool.newBuilder().setVersion("0.11.0")).build()).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withSigningConfig(SigningConfiguration.builder().setSignerConfig(privateKey, certificate).build()).build());
buildApksManager.execute();
try (ZipFile apkSet = new ZipFile(outputFilePath.toFile())) {
BuildApksResult result = extractTocFromApkSetFile(apkSet, outputDir);
ImmutableList<ApkDescription> apkDescriptions = apkDescriptions(result.getVariantList());
assertThat(apkDescriptions).isNotEmpty();
for (ApkDescription apkDescription : apkDescriptions) {
ImmutableSet<String> filesInApk = filesInApk(apkDescription, apkSet);
assertThat(filesInApk).doesNotContain(String.format("META-INF/%s.RSA", SIGNER_CONFIG_NAME));
}
}
}
use of com.android.bundle.Commands.ApkDescription in project bundletool by google.
the class BuildApksManagerTest method splits_assetMixedTextureTargetingWithSuffixStripped_assetModule.
@Test
public void splits_assetMixedTextureTargetingWithSuffixStripped_assetModule() throws Exception {
// Create a bundle with assets containing both ETC1 textures and textures without
// targeting specified.
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.test.app"))).addModule("tcf_assets", builder -> builder.addFile("assets/textures/untargeted_texture.dat").addFile("assets/textures#tcf_etc1/etc1_texture.dat").setAssetsConfig(assets(targetedAssetsDirectory("assets/textures", assetsDirectoryTargeting(alternativeTextureCompressionTargeting(ETC1_RGB8))), targetedAssetsDirectory("assets/textures#tcf_etc1", assetsDirectoryTargeting(textureCompressionTargeting(ETC1_RGB8))))).setManifest(androidManifestForAssetModule("com.test.app"))).setBundleConfig(BundleConfigBuilder.create().addSplitDimension(Value.TEXTURE_COMPRESSION_FORMAT, /* negate= */
false, /* stripSuffix= */
true, /* defaultSuffix= */
"etc1").build()).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(result.getAssetSliceSetList()).hasSize(1);
List<ApkDescription> assetApks = result.getAssetSliceSet(0).getApkDescriptionList();
// Check that apks for ETC1 and "Other TCF" have been created
ImmutableList<ApkDescription> tcfSplits = assetApks.stream().filter(apkDesc -> apkDesc.getTargeting().hasTextureCompressionFormatTargeting()).collect(toImmutableList());
assertThat(apkNamesInApkDescriptions(tcfSplits)).containsExactly("tcf_assets-other_tcf.apk", "tcf_assets-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");
assertThat(files).doesNotContain("assets/textures#tcf_etc1/etc1_texture.dat");
} else {
// The "ETC1" split contains the ETC1 texture only.
TextureCompressionFormat format = textureFormatTargeting.getValueList().get(0);
assertThat(format.getAlias()).isEqualTo(ETC1_RGB8);
// Suffix stripping was enabled, so "textures#tcf_etc1" folder is now renamed to "textures".
assertThat(files).contains("assets/textures/etc1_texture.dat");
assertThat(files).doesNotContain("assets/textures#tcf_etc1/etc1_texture.dat");
assertThat(files).doesNotContain("assets/textures/untargeted_texture.dat");
}
}
}
use of com.android.bundle.Commands.ApkDescription in project bundletool by google.
the class BuildApksManagerTest method pinningOfManifestReachableResources_disabled.
@Test
@Theory
public void pinningOfManifestReachableResources_disabled(@FromDataPoints("manifestReachableResourcesDisabledVersions") Version bundleVersion) throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("res/drawable-mdpi/manifest_image.jpg").addFile("res/drawable-hdpi/manifest_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")).build())).setBundleConfig(BundleConfigBuilder.create().setVersion(bundleVersion.toString()).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);
ImmutableList<ApkDescription> masterSplits = splitApks.stream().filter(apkDesc -> apkDesc.getSplitApkMetadata().getIsMasterSplit()).collect(toImmutableList());
assertThat(masterSplits).isNotEmpty();
for (ApkDescription masterSplit : masterSplits) {
assertThat(filesInApk(masterSplit, apkSetFile)).doesNotContain("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)).containsAnyOf("res/drawable-mdpi/manifest_image.jpg", "res/drawable-hdpi/manifest_image.jpg");
}
}
use of com.android.bundle.Commands.ApkDescription in project bundletool by google.
the class BuildApksManagerTest method splits_assetTextureCompressionFormatDisabled.
@Test
public void splits_assetTextureCompressionFormatDisabled() throws Exception {
Path bundlePath = createAppBundleWithBaseModuleWithTextureTargeting(false, false);
TestComponent.useTestModule(this, createTestModuleBuilder().withBundlePath(bundlePath).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);
assertThat(splitApkVariant.getApkSetList()).hasSize(1);
assertThat(apkNamesInVariant(splitApkVariant)).containsExactly("base-master.apk");
ImmutableList<ApkDescription> tcfSplits = splitApks.stream().filter(apkDesc -> apkDesc.getTargeting().hasTextureCompressionFormatTargeting()).collect(toImmutableList());
assertThat(tcfSplits).isEmpty();
ApkDescription masterSplit = splitApks.stream().filter(apkDesc -> apkDesc.getSplitApkMetadata().getIsMasterSplit()).collect(onlyElement());
assertThat(filesInApk(masterSplit, apkSetFile)).containsAtLeast("assets/textures#tcf_atc/texture.dat", "assets/textures#tcf_etc1/texture.dat");
}
use of com.android.bundle.Commands.ApkDescription in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_universal_generatesSingleApkWithAllTcfAssets.
@Test
public void buildApksCommand_universal_generatesSingleApkWithAllTcfAssets() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.test.app"))).addModule("tcf_assets", builder -> builder.addFile("assets/textures#tcf_atc/texture.dat").addFile("assets/textures#tcf_etc1/texture.dat").setAssetsConfig(assets(targetedAssetsDirectory("assets/textures#tcf_atc", assetsDirectoryTargeting(textureCompressionTargeting(ATC))), targetedAssetsDirectory("assets/textures#tcf_etc1", assetsDirectoryTargeting(textureCompressionTargeting(ETC1_RGB8))))).setManifest(androidManifestForAssetModule("com.test.app", withInstallTimeDelivery()))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withApkBuildMode(UNIVERSAL).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(standaloneApkVariants(result)).hasSize(1);
Variant universalVariant = standaloneApkVariants(result).get(0);
assertThat(apkDescriptions(universalVariant)).hasSize(1);
ApkDescription universalApk = apkDescriptions(universalVariant).get(0);
// Check APK content
File universalApkFile = extractFromApkSetFile(apkSetFile, universalApk.getPath(), outputDir);
try (ZipFile universalApkZipFile = new ZipFile(universalApkFile)) {
// Even if we used targeted folders, they are all included because we did not activate
// texture targeting optimization.
assertThat(filesUnderPath(universalApkZipFile, ASSETS_DIRECTORY)).containsExactly("assets/textures#tcf_atc/texture.dat", "assets/textures#tcf_etc1/texture.dat");
}
}
Aggregations