Add the --rename-manifest-package option to aapt.
It allows you to force override the manifest package listed in the AndroidManifest.xml when creating an APK file. Change-Id: I7eac7943c4e56610b65728ae54773a273634fd9d
This commit is contained in:
@@ -38,7 +38,7 @@ public:
|
||||
mUpdate(false), mExtending(false),
|
||||
mRequireLocalization(false), mPseudolocalize(false),
|
||||
mUTF8(false), mEncodingSpecified(false), mValues(false),
|
||||
mCompressionMethod(0), mOutputAPKFile(NULL),
|
||||
mCompressionMethod(0), mOutputAPKFile(NULL), mManifestPackageNameOverride(NULL),
|
||||
mAssetSourceDir(NULL), mProguardFile(NULL),
|
||||
mAndroidManifestFile(NULL), mPublicOutputFile(NULL),
|
||||
mRClassDir(NULL), mResourceIntermediatesDir(NULL),
|
||||
@@ -88,6 +88,8 @@ public:
|
||||
void setJunkPath(bool val) { mJunkPath = val; }
|
||||
const char* getOutputAPKFile() const { return mOutputAPKFile; }
|
||||
void setOutputAPKFile(const char* val) { mOutputAPKFile = val; }
|
||||
const char* getManifestPackageNameOverride() const { return mManifestPackageNameOverride; }
|
||||
void setManifestPackageNameOverride(const char * val) { mManifestPackageNameOverride = val; }
|
||||
|
||||
/*
|
||||
* Input options.
|
||||
@@ -178,6 +180,7 @@ private:
|
||||
int mCompressionMethod;
|
||||
bool mJunkPath;
|
||||
const char* mOutputAPKFile;
|
||||
const char* mManifestPackageNameOverride;
|
||||
const char* mAssetSourceDir;
|
||||
const char* mProguardFile;
|
||||
const char* mAndroidManifestFile;
|
||||
|
||||
@@ -436,6 +436,15 @@ int main(int argc, char* const argv[])
|
||||
} else if (strcmp(cp, "-utf16") == 0) {
|
||||
bundle.setEncodingSpecified(true);
|
||||
bundle.setUTF8(false);
|
||||
} else if (strcmp(cp, "-rename-manifest-package") == 0) {
|
||||
argc--;
|
||||
argv++;
|
||||
if (!argc) {
|
||||
fprintf(stderr, "ERROR: No argument supplied for '--rename-manifest-package' option\n");
|
||||
wantUsage = true;
|
||||
goto bail;
|
||||
}
|
||||
bundle.setManifestPackageNameOverride(argv[0]);
|
||||
} else {
|
||||
fprintf(stderr, "ERROR: Unknown option '-%s'\n", cp);
|
||||
wantUsage = true;
|
||||
|
||||
@@ -489,11 +489,11 @@ static bool applyFileOverlay(Bundle *bundle,
|
||||
DefaultKeyedVector<AaptGroupEntry, sp<AaptFile> > baseFiles =
|
||||
baseGroup->getFiles();
|
||||
for (size_t i=0; i < baseFiles.size(); i++) {
|
||||
printf("baseFile %d has flavor %s\n", i,
|
||||
printf("baseFile %ld has flavor %s\n", i,
|
||||
baseFiles.keyAt(i).toString().string());
|
||||
}
|
||||
for (size_t i=0; i < overlayFiles.size(); i++) {
|
||||
printf("overlayFile %d has flavor %s\n", i,
|
||||
printf("overlayFile %ld has flavor %s\n", i,
|
||||
overlayFiles.keyAt(i).toString().string());
|
||||
}
|
||||
}
|
||||
@@ -507,7 +507,7 @@ static bool applyFileOverlay(Bundle *bundle,
|
||||
keyAt(overlayGroupIndex));
|
||||
if(baseFileIndex < UNKNOWN_ERROR) {
|
||||
if (bundle->getVerbose()) {
|
||||
printf("found a match (%d) for overlay file %s, for flavor %s\n",
|
||||
printf("found a match (%ld) for overlay file %s, for flavor %s\n",
|
||||
baseFileIndex,
|
||||
overlayGroup->getLeaf().string(),
|
||||
overlayFiles.keyAt(overlayGroupIndex).toString().string());
|
||||
@@ -562,6 +562,33 @@ void addTagAttribute(const sp<XMLNode>& node, const char* ns8,
|
||||
node->addAttribute(ns, attr, String16(value));
|
||||
}
|
||||
|
||||
static void fullyQualifyClassName(String8& package, sp<XMLNode> node) {
|
||||
XMLNode::attribute_entry* attr = node->editAttribute(
|
||||
String16("http://schemas.android.com/apk/res/android"), String16("name"));
|
||||
if (attr != NULL) {
|
||||
String8 name(attr->string);
|
||||
|
||||
// asdf --> package.asdf
|
||||
// .asdf .a.b --> package.asdf package.a.b
|
||||
// asdf.adsf --> asdf.asdf
|
||||
String8 className;
|
||||
const char* p = name.string();
|
||||
const char* q = strchr(p, '.');
|
||||
if (p == q) {
|
||||
className += package;
|
||||
className += name;
|
||||
} else if (q == NULL) {
|
||||
className += package;
|
||||
className += ".";
|
||||
className += name;
|
||||
} else {
|
||||
className += name;
|
||||
}
|
||||
NOISY(printf("Qualifying class '%s' to '%s'", name.string(), className.string()));
|
||||
attr->string.setTo(String16(className));
|
||||
}
|
||||
}
|
||||
|
||||
status_t massageManifest(Bundle* bundle, sp<XMLNode> root)
|
||||
{
|
||||
root = root->searchElement(String16(), String16("manifest"));
|
||||
@@ -591,7 +618,36 @@ status_t massageManifest(Bundle* bundle, sp<XMLNode> root)
|
||||
addTagAttribute(vers, RESOURCES_ANDROID_NAMESPACE, "maxSdkVersion",
|
||||
bundle->getMaxSdkVersion());
|
||||
}
|
||||
|
||||
|
||||
// Deal with manifest package name overrides
|
||||
const char* manifestPackageNameOverride = bundle->getManifestPackageNameOverride();
|
||||
if (manifestPackageNameOverride != NULL) {
|
||||
// Update the actual package name
|
||||
XMLNode::attribute_entry* attr = root->editAttribute(String16(), String16("package"));
|
||||
if (attr == NULL) {
|
||||
fprintf(stderr, "package name is required with --rename-manifest-package.\n");
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
String8 origPackage(attr->string);
|
||||
attr->string.setTo(String16(manifestPackageNameOverride));
|
||||
NOISY(printf("Overriding package '%s' to be '%s'\n", origPackage.string(), manifestPackageNameOverride));
|
||||
|
||||
// Make class names fully qualified
|
||||
sp<XMLNode> application = root->getChildElement(String16(), String16("application"));
|
||||
if (application != NULL) {
|
||||
fullyQualifyClassName(origPackage, application);
|
||||
|
||||
Vector<sp<XMLNode> >& children = const_cast<Vector<sp<XMLNode> >&>(application->getChildren());
|
||||
for (size_t i = 0; i < children.size(); i++) {
|
||||
sp<XMLNode> child = children.editItemAt(i);
|
||||
String8 tag(child->getElementName());
|
||||
if (tag == "activity" || tag == "service" || tag == "receiver" || tag == "provider") {
|
||||
fullyQualifyClassName(origPackage, child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -1173,14 +1229,14 @@ status_t buildResources(Bundle* bundle, const sp<AaptAssets>& assets)
|
||||
table.writePublicDefinitions(String16(assets->getPackage()), fp);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
#if 0
|
||||
NOISY(
|
||||
ResTable rt;
|
||||
rt.add(resFile->getData(), resFile->getSize(), NULL);
|
||||
printf("Generated resources:\n");
|
||||
rt.print();
|
||||
)
|
||||
|
||||
#endif
|
||||
// These resources are now considered to be a part of the included
|
||||
// resources, for others to reference.
|
||||
err = assets->addIncludedResources(resFile);
|
||||
|
||||
@@ -25,7 +25,7 @@ void printStringPool(const ResStringPool* pool)
|
||||
const size_t NS = pool->size();
|
||||
for (size_t s=0; s<NS; s++) {
|
||||
size_t len;
|
||||
printf("String #%d: %s\n", s,
|
||||
printf("String #%ld: %s\n", s,
|
||||
String8(pool->stringAt(s, &len)).string());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -555,6 +555,19 @@ const XMLNode::attribute_entry* XMLNode::getAttribute(const String16& ns,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
XMLNode::attribute_entry* XMLNode::editAttribute(const String16& ns,
|
||||
const String16& name)
|
||||
{
|
||||
for (size_t i=0; i<mAttributes.size(); i++) {
|
||||
attribute_entry * ae = &mAttributes.editItemAt(i);
|
||||
if (ae->ns == ns && ae->name == name) {
|
||||
return ae;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const String16& XMLNode::getCData() const
|
||||
{
|
||||
return mChars;
|
||||
|
||||
@@ -95,6 +95,8 @@ public:
|
||||
|
||||
const attribute_entry* getAttribute(const String16& ns, const String16& name) const;
|
||||
|
||||
attribute_entry* editAttribute(const String16& ns, const String16& name);
|
||||
|
||||
const String16& getCData() const;
|
||||
|
||||
const String16& getComment() const;
|
||||
|
||||
Reference in New Issue
Block a user