diff --git a/tools/aapt/Resource.cpp b/tools/aapt/Resource.cpp index 3d93bbe62f678..963c7962fdbb6 100644 --- a/tools/aapt/Resource.cpp +++ b/tools/aapt/Resource.cpp @@ -900,8 +900,8 @@ status_t updatePreProcessedCache(Bundle* bundle) return 0; } -status_t generateAndroidManifestForSplit(const String16& package, const sp& split, - sp& outFile) { +status_t generateAndroidManifestForSplit(Bundle* bundle, const sp& assets, + const sp& split, sp& outFile, ResourceTable* table) { const String8 filename("AndroidManifest.xml"); const String16 androidPrefix("android"); const String16 androidNSUri("http://schemas.android.com/apk/res/android"); @@ -910,8 +910,19 @@ status_t generateAndroidManifestForSplit(const String16& package, const sp tag sp manifest = XMLNode::newElement(filename, String16(), String16("manifest")); - // Add the 'package' attribute which is set to the original package name. - manifest->addAttribute(String16(), String16("package"), package); + // Add the 'package' attribute which is set to the package name. + const char* packageName = assets->getPackage(); + const char* manifestPackageNameOverride = bundle->getManifestPackageNameOverride(); + if (manifestPackageNameOverride != NULL) { + packageName = manifestPackageNameOverride; + } + manifest->addAttribute(String16(), String16("package"), String16(packageName)); + + // Add the 'versionCode' attribute which is set to the original version code. + if (!addTagAttribute(manifest, RESOURCES_ANDROID_NAMESPACE, "versionCode", + bundle->getVersionCode(), true, true)) { + return UNKNOWN_ERROR; + } // Add the 'split' attribute which describes the configurations included. String8 splitName("config_"); @@ -923,8 +934,8 @@ status_t generateAndroidManifestForSplit(const String16& package, const spaddChild(app); root->addChild(manifest); - status_t err = root->flatten(outFile, true, true); - if (err != NO_ERROR) { + int err = compileXmlFile(assets, root, outFile, table); + if (err < NO_ERROR) { return err; } outFile->setCompressionMethod(ZipEntry::kCompressDeflated); @@ -1371,8 +1382,8 @@ status_t buildResources(Bundle* bundle, const sp& assets, sp generatedManifest = new AaptFile(String8("AndroidManifest.xml"), AaptGroupEntry(), String8()); - err = generateAndroidManifestForSplit(String16(assets->getPackage()), split, - generatedManifest); + err = generateAndroidManifestForSplit(bundle, assets, split, + generatedManifest, &table); if (err != NO_ERROR) { fprintf(stderr, "Failed to generate AndroidManifest.xml for split '%s'\n", split->getPrintableName().string());