From 2cfc8482267707a671cbe4275ea8927c1aef991a Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Wed, 9 Jul 2014 16:10:16 -0700 Subject: [PATCH] Add versionCode to split manifest; compile. To verify consistency at install time, all APK manifests must declare the same package name and version code. Also start compiling the manifest, since versionCode is an attribute. Bug: 14975160 Change-Id: I2a1a769bd3dfde05b19563af5ca9b6c15a9c95ff --- tools/aapt/Resource.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) 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());