use of com.android.tools.build.bundletool.testing.ResourcesTableFactory.TEST_LABEL_RESOURCE_ID in project bundletool by google.
the class BuildApksValidationTest method splits_textureDefaultSuffixNotPresentInAssetPacks.
@Test
public void splits_textureDefaultSuffixNotPresentInAssetPacks() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.test.app")).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("feature_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(androidManifestForFeature("com.test.app", withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).setBundleConfig(BundleConfigBuilder.create().addSplitDimension(Value.TEXTURE_COMPRESSION_FORMAT, /* negate= */
false, /* stripSuffix= */
false, /* defaultSuffix= */
"astc").build()).build();
new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).build();
// ASTC format is not present in one module with TCF targeting, so we'll
// consider the bundle invalid as the configuration specified that this is the default
// format to use for generating standalone or universal APKs.
InvalidBundleException exception = assertThrows(InvalidBundleException.class, command::execute);
assertThat(exception).hasMessageThat().contains("the texture folders for format 'ASTC' will be used, but module 'feature_tcf_assets'" + " has no such folders");
}
use of com.android.tools.build.bundletool.testing.ResourcesTableFactory.TEST_LABEL_RESOURCE_ID in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_standalone_noTextureTargeting.
@Test
public void buildApksCommand_standalone_noTextureTargeting() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.test.app")).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("feature_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(androidManifestForFeature("com.test.app", withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withOptimizationDimensions(TEXTURE_COMPRESSION_FORMAT).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(standaloneApkVariants(result)).hasSize(1);
assertThat(apkDescriptions(standaloneApkVariants(result))).hasSize(1);
ApkDescription shard = apkDescriptions(standaloneApkVariants(result)).get(0);
assertThat(apkSetFile).hasFile(shard.getPath());
try (ZipFile shardZip = new ZipFile(extractFromApkSetFile(apkSetFile, shard.getPath(), outputDir))) {
// Even if we used targeted folders, they are all included because we did not activate
// texture targeting optimization.
assertThat(shardZip).hasFile("assets/textures#tcf_atc/texture.dat");
assertThat(shardZip).hasFile("assets/textures#tcf_etc1/texture.dat");
// Suffix stripping was NOT applied (because again we did not even activate texture targeting
// optimization).
assertThat(shardZip).doesNotHaveFile("assets/textures/texture.dat");
}
}
use of com.android.tools.build.bundletool.testing.ResourcesTableFactory.TEST_LABEL_RESOURCE_ID in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_standalone_mixedTextureTargetingWithSuffixStripped.
@Test
public void buildApksCommand_standalone_mixedTextureTargetingWithSuffixStripped() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.test.app")).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("feature_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(androidManifestForFeature("com.test.app", withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).setBundleConfig(BundleConfigBuilder.create().addSplitDimension(Value.TEXTURE_COMPRESSION_FORMAT, /* negate= */
false, /* stripSuffix= */
true, /* defaultSuffix= */
"etc1").build()).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withOptimizationDimensions(TEXTURE_COMPRESSION_FORMAT).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(standaloneApkVariants(result)).hasSize(1);
assertThat(apkDescriptions(standaloneApkVariants(result))).hasSize(1);
ApkDescription shard = apkDescriptions(standaloneApkVariants(result)).get(0);
// Check APK content
assertThat(apkSetFile).hasFile(shard.getPath());
try (ZipFile shardZip = new ZipFile(extractFromApkSetFile(apkSetFile, shard.getPath(), outputDir))) {
assertThat(shardZip).hasFile("assets/textures/etc1_texture.dat");
assertThat(shardZip).doesNotHaveFile("assets/textures#tcf_etc1/etc1_texture.dat");
assertThat(shardZip).doesNotHaveFile("assets/textures/untargeted_texture.dat");
}
// Check that targeting was applied to both the APK and the variant
assertThat(standaloneApkVariants(result).get(0).getTargeting().getTextureCompressionFormatTargeting().getValueList()).containsExactly(textureCompressionFormat(ETC1_RGB8));
assertThat(shard.getTargeting().getTextureCompressionFormatTargeting().getValueList()).containsExactly(textureCompressionFormat(ETC1_RGB8));
}
use of com.android.tools.build.bundletool.testing.ResourcesTableFactory.TEST_LABEL_RESOURCE_ID in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_standalone_mergesDexFiles.
@Test
public void buildApksCommand_standalone_mergesDexFiles() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("dex/classes.dex", TestData.readBytes("testdata/dex/classes.dex")).setManifest(androidManifest("com.test.app")).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("module", builder -> builder.addFile("dex/classes.dex", TestData.readBytes("testdata/dex/classes-other.dex")).setManifest(androidManifestForFeature("com.test.app", withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(standaloneApkVariants(result)).hasSize(1);
Variant standaloneApkVariant = standaloneApkVariants(result).get(0);
assertThat(standaloneApkVariant.getApkSetList()).hasSize(1);
ApkSet shards = standaloneApkVariant.getApkSet(0);
assertThat(shards.getModuleMetadata().getName()).isEqualTo("base");
assertThat(shards.getApkDescriptionList()).hasSize(1);
ApkDescription shard = shards.getApkDescription(0);
assertThat(apkSetFile).hasFile(shard.getPath());
assertThat(ZipPath.create(shard.getPath()).getFileName()).isEqualTo(ZipPath.create("standalone.apk"));
try (ZipFile shardZip = new ZipFile(extractFromApkSetFile(apkSetFile, shard.getPath(), outputDir))) {
assertThat(shardZip).hasFile("classes.dex");
byte[] mergedDexData = ByteStreams.toByteArray(shardZip.getInputStream(new ZipEntry("classes.dex")));
assertThat(mergedDexData.length).isGreaterThan(0);
assertThat(mergedDexData).isNotEqualTo(TestData.readBytes("testdata/dex/classes.dex"));
assertThat(mergedDexData).isNotEqualTo(TestData.readBytes("testdata/dex/classes-other.dex"));
}
}
use of com.android.tools.build.bundletool.testing.ResourcesTableFactory.TEST_LABEL_RESOURCE_ID in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_universal_selectsRightModulesForMerging.
@Test
public void buildApksCommand_universal_selectsRightModulesForMerging() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("assets/a.txt").setManifest(androidManifest("com.test.app")).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("feature", builder -> builder.addFile("assets/b.txt").setManifest(androidManifestForFeature("com.test.app", withFusingAttribute(true), withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).addModule("not_fused", builder -> builder.addFile("assets/c.txt").setManifest(androidManifestForFeature("com.test.app", withFusingAttribute(false), withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).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(result.getVariantList()).hasSize(1);
assertThat(splitApkVariants(result)).isEmpty();
assertThat(standaloneApkVariants(result)).hasSize(1);
Variant universalVariant = standaloneApkVariants(result).get(0);
assertThat(apkDescriptions(universalVariant)).hasSize(1);
ApkDescription universalApk = apkDescriptions(universalVariant).get(0);
// Correct modules selected for merging.
assertThat(universalApk.getStandaloneApkMetadata().getFusedModuleNameList()).containsExactly("base", "feature");
File universalApkFile = extractFromApkSetFile(apkSetFile, universalApk.getPath(), outputDir);
try (ZipFile universalApkZipFile = new ZipFile(universalApkFile)) {
assertThat(filesUnderPath(universalApkZipFile, ZipPath.create("assets"))).containsExactly("assets/a.txt", "assets/b.txt");
}
}
Aggregations