use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.
the class ResourceAnalyzerTest method transitive_item_xmlFileWithResourceReference.
@Test
public void transitive_item_xmlFileWithResourceReference() throws Exception {
// AndroidManifest --> 0x7f010001 (xml file) --> 0x7f020002 (string)
XmlNode manifest = AndroidManifest.create(xmlNode(xmlElement("manifest", xmlNode(xmlElement("application", xmlResourceReferenceAttribute(NO_NAMESPACE_URI, "attr_pointing_to_xml", /* attrResourceId= */
0x999999, /* valueResourceId= */
0x7f010001)))))).getManifestRoot().getProto();
XmlNode embeddedXmlFile = AndroidManifest.create(xmlNode(xmlElement("root", xmlResourceReferenceAttribute(ANDROID_NAMESPACE_URI, "name", /* attrResourceId= */
0x999999, /* valueResourceId= */
0x7f020002)))).getManifestRoot().getProto();
ResourceTable resourceTable = resourceTable(pkg(0x7f, "com.test.app", type(0x01, "file", entry(0x0001, "xml_file", fileReference("res/xml/embedded.xml", FileReference.Type.PROTO_XML, DEFAULT_CONFIG))), type(0x02, "string", entry(0x0002, "name_str", value("hello", DEFAULT_CONFIG)), entry(0x0099, "not_referenced", value("", DEFAULT_CONFIG)))));
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(manifest).setResourceTable(resourceTable).addFile("res/xml/embedded.xml", embeddedXmlFile.toByteArray())).build();
ImmutableSet<ResourceId> resourceIds = new ResourceAnalyzer(appBundle).findAllAppResourcesReachableFromBaseManifest();
assertThat(resourceIds).containsExactly(ResourceId.create(0x7f010001), ResourceId.create(0x7f020002));
}
use of com.android.tools.build.bundletool.model.AndroidManifest 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.model.AndroidManifest in project bundletool by google.
the class BuildApksManagerTest method splitNames_assetLanguages.
@Test
public void splitNames_assetLanguages() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("dex/classes.dex").addFile("assets/paks#lang_es/es.pak").addFile("assets/paks/en.pak").setManifest(androidManifest("com.test.app")).setAssetsConfig(assets(targetedAssetsDirectory("assets/paks#lang_es", assetsDirectoryTargeting(languageTargeting("es"))), targetedAssetsDirectory("assets/paks", assetsDirectoryTargeting(alternativeLanguageTargeting("es")))))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(splitApkVariants(result)).hasSize(1);
Variant splitApkVariant = splitApkVariants(result).get(0);
assertThat(splitApkVariant.getApkSetList()).hasSize(1);
assertThat(apkNamesInVariant(splitApkVariant)).containsExactly("base-master.apk", "base-es.apk", "base-other_lang.apk");
}
use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.
the class BuildApksManagerTest method apkModifier_modifyingVersionCode.
@Test
public void apkModifier_modifyingVersionCode() throws Exception {
TestComponent.useTestModule(this, createTestModuleBuilder().withOutputPath(outputFilePath).withApkModifier(new ApkModifier() {
@Override
public AndroidManifest modifyManifest(AndroidManifest manifest, ApkModifier.ApkDescription apkDescription) {
return manifest.toEditor().setVersionCode(1000 + apkDescription.getVariantNumber()).save();
}
}).build());
buildApksManager.execute();
ZipFile apkSet = openZipFile(outputFilePath.toFile());
File standaloneApk = extractFromApkSetFile(apkSet, "standalones/standalone.apk", outputDir);
File masterSplitApk = extractFromApkSetFile(apkSet, "splits/base-master.apk", outputDir);
assertThat(extractVersionCode(standaloneApk)).isEqualTo(1000);
assertThat(extractVersionCode(masterSplitApk)).isEqualTo(1001);
}
use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_standalone_mixedTextureTargetingInDifferentPacksWithSameFolderNameAndNonFallbackDefault.
@Test
public void buildApksCommand_standalone_mixedTextureTargetingInDifferentPacksWithSameFolderNameAndNonFallbackDefault() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.test.app", withFusingAttribute(true)))).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(androidManifest("com.test.app", withDelivery(DeliveryType.INSTALL_TIME), withFusingAttribute(true)))).addModule("feature_assets_without_tcf", builder -> builder.addFile("assets/textures/another_untargeted_texture.dat").setAssetsConfig(assets(targetedAssetsDirectory("assets/textures", AssetsDirectoryTargeting.getDefaultInstance()))).setManifest(androidManifest("com.test.app", withDelivery(DeliveryType.INSTALL_TIME), withFusingAttribute(true)))).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());
InvalidBundleException e = assertThrows(InvalidBundleException.class, () -> buildApksManager.execute());
assertThat(e).hasMessageThat().contains("Encountered conflicting targeting values while merging assets config.");
}
Aggregations