* commit 'cc9747ed45302956a3ec9dd21f7b950b837dbfdd': Add --error-on-failed-insert option to aapt.
This commit is contained in:
@ -61,7 +61,7 @@ public:
|
|||||||
mMinSdkVersion(NULL), mTargetSdkVersion(NULL), mMaxSdkVersion(NULL),
|
mMinSdkVersion(NULL), mTargetSdkVersion(NULL), mMaxSdkVersion(NULL),
|
||||||
mVersionCode(NULL), mVersionName(NULL), mCustomPackage(NULL), mExtraPackages(NULL),
|
mVersionCode(NULL), mVersionName(NULL), mCustomPackage(NULL), mExtraPackages(NULL),
|
||||||
mMaxResVersion(NULL), mDebugMode(false), mNonConstantId(false), mProduct(NULL),
|
mMaxResVersion(NULL), mDebugMode(false), mNonConstantId(false), mProduct(NULL),
|
||||||
mUseCrunchCache(false), mArgc(0), mArgv(NULL)
|
mUseCrunchCache(false), mErrorOnFailedInsert(false), mArgc(0), mArgv(NULL)
|
||||||
{}
|
{}
|
||||||
~Bundle(void) {}
|
~Bundle(void) {}
|
||||||
|
|
||||||
@ -110,6 +110,8 @@ public:
|
|||||||
void setAutoAddOverlay(bool val) { mAutoAddOverlay = val; }
|
void setAutoAddOverlay(bool val) { mAutoAddOverlay = val; }
|
||||||
bool getGenDependencies() { return mGenDependencies; }
|
bool getGenDependencies() { return mGenDependencies; }
|
||||||
void setGenDependencies(bool val) { mGenDependencies = val; }
|
void setGenDependencies(bool val) { mGenDependencies = val; }
|
||||||
|
bool getErrorOnFailedInsert() { return mErrorOnFailedInsert; }
|
||||||
|
void setErrorOnFailedInsert(bool val) { mErrorOnFailedInsert = val; }
|
||||||
|
|
||||||
bool getUTF16StringsOption() {
|
bool getUTF16StringsOption() {
|
||||||
return mWantUTF16 || !isMinSdkAtLeast(SDK_FROYO);
|
return mWantUTF16 || !isMinSdkAtLeast(SDK_FROYO);
|
||||||
@ -276,6 +278,7 @@ private:
|
|||||||
bool mNonConstantId;
|
bool mNonConstantId;
|
||||||
const char* mProduct;
|
const char* mProduct;
|
||||||
bool mUseCrunchCache;
|
bool mUseCrunchCache;
|
||||||
|
bool mErrorOnFailedInsert;
|
||||||
|
|
||||||
/* file specification */
|
/* file specification */
|
||||||
int mArgc;
|
int mArgc;
|
||||||
|
@ -177,6 +177,11 @@ void usage(void)
|
|||||||
" Make the resources ID non constant. This is required to make an R java class\n"
|
" Make the resources ID non constant. This is required to make an R java class\n"
|
||||||
" that does not contain the final value but is used to make reusable compiled\n"
|
" that does not contain the final value but is used to make reusable compiled\n"
|
||||||
" libraries that need to access resources.\n"
|
" libraries that need to access resources.\n"
|
||||||
|
" --error-on-failed-insert\n"
|
||||||
|
" Forces aapt to return an error if it fails to insert values into the manifest\n"
|
||||||
|
" with --debug-mode, --min-sdk-version, --target-sdk-version --version-code\n"
|
||||||
|
" and --version-name.\n"
|
||||||
|
" Insertion typically fails if the manifest already defines the attribute.\n"
|
||||||
" --ignore-assets\n"
|
" --ignore-assets\n"
|
||||||
" Assets to be ignored. Default pattern is:\n"
|
" Assets to be ignored. Default pattern is:\n"
|
||||||
" %s\n",
|
" %s\n",
|
||||||
@ -542,6 +547,8 @@ int main(int argc, char* const argv[])
|
|||||||
bundle.setInstrumentationPackageNameOverride(argv[0]);
|
bundle.setInstrumentationPackageNameOverride(argv[0]);
|
||||||
} else if (strcmp(cp, "-auto-add-overlay") == 0) {
|
} else if (strcmp(cp, "-auto-add-overlay") == 0) {
|
||||||
bundle.setAutoAddOverlay(true);
|
bundle.setAutoAddOverlay(true);
|
||||||
|
} else if (strcmp(cp, "-error-on-failed-insert") == 0) {
|
||||||
|
bundle.setErrorOnFailedInsert(true);
|
||||||
} else if (strcmp(cp, "-product") == 0) {
|
} else if (strcmp(cp, "-product") == 0) {
|
||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
|
@ -673,24 +673,40 @@ static bool applyFileOverlay(Bundle *bundle,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addTagAttribute(const sp<XMLNode>& node, const char* ns8,
|
/*
|
||||||
const char* attr8, const char* value)
|
* Inserts an attribute in a given node, only if the attribute does not
|
||||||
|
* exist.
|
||||||
|
* If errorOnFailedInsert is true, and the attribute already exists, returns false.
|
||||||
|
* Returns true otherwise, even if the attribute already exists.
|
||||||
|
*/
|
||||||
|
bool addTagAttribute(const sp<XMLNode>& node, const char* ns8,
|
||||||
|
const char* attr8, const char* value, bool errorOnFailedInsert)
|
||||||
{
|
{
|
||||||
if (value == NULL) {
|
if (value == NULL) {
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const String16 ns(ns8);
|
const String16 ns(ns8);
|
||||||
const String16 attr(attr8);
|
const String16 attr(attr8);
|
||||||
|
|
||||||
if (node->getAttribute(ns, attr) != NULL) {
|
if (node->getAttribute(ns, attr) != NULL) {
|
||||||
|
if (errorOnFailedInsert) {
|
||||||
|
fprintf(stderr, "Error: AndroidManifest.xml already defines %s (in %s);"
|
||||||
|
" cannot insert new value %s.\n",
|
||||||
|
String8(attr).string(), String8(ns).string(), value);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Warning: AndroidManifest.xml already defines %s (in %s);"
|
fprintf(stderr, "Warning: AndroidManifest.xml already defines %s (in %s);"
|
||||||
" using existing value in manifest.\n",
|
" using existing value in manifest.\n",
|
||||||
String8(attr).string(), String8(ns).string());
|
String8(attr).string(), String8(ns).string());
|
||||||
return;
|
|
||||||
|
// don't stop the build.
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
node->addAttribute(ns, attr, String16(value));
|
node->addAttribute(ns, attr, String16(value));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fullyQualifyClassName(const String8& package, sp<XMLNode> node,
|
static void fullyQualifyClassName(const String8& package, sp<XMLNode> node,
|
||||||
@ -728,11 +744,17 @@ status_t massageManifest(Bundle* bundle, sp<XMLNode> root)
|
|||||||
fprintf(stderr, "No <manifest> tag.\n");
|
fprintf(stderr, "No <manifest> tag.\n");
|
||||||
return UNKNOWN_ERROR;
|
return UNKNOWN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
addTagAttribute(root, RESOURCES_ANDROID_NAMESPACE, "versionCode",
|
bool errorOnFailedInsert = bundle->getErrorOnFailedInsert();
|
||||||
bundle->getVersionCode());
|
|
||||||
addTagAttribute(root, RESOURCES_ANDROID_NAMESPACE, "versionName",
|
if (!addTagAttribute(root, RESOURCES_ANDROID_NAMESPACE, "versionCode",
|
||||||
bundle->getVersionName());
|
bundle->getVersionCode(), errorOnFailedInsert)) {
|
||||||
|
return UNKNOWN_ERROR;
|
||||||
|
}
|
||||||
|
if (!addTagAttribute(root, RESOURCES_ANDROID_NAMESPACE, "versionName",
|
||||||
|
bundle->getVersionName(), errorOnFailedInsert)) {
|
||||||
|
return UNKNOWN_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
if (bundle->getMinSdkVersion() != NULL
|
if (bundle->getMinSdkVersion() != NULL
|
||||||
|| bundle->getTargetSdkVersion() != NULL
|
|| bundle->getTargetSdkVersion() != NULL
|
||||||
@ -743,18 +765,27 @@ status_t massageManifest(Bundle* bundle, sp<XMLNode> root)
|
|||||||
root->insertChildAt(vers, 0);
|
root->insertChildAt(vers, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
addTagAttribute(vers, RESOURCES_ANDROID_NAMESPACE, "minSdkVersion",
|
if (!addTagAttribute(vers, RESOURCES_ANDROID_NAMESPACE, "minSdkVersion",
|
||||||
bundle->getMinSdkVersion());
|
bundle->getMinSdkVersion(), errorOnFailedInsert)) {
|
||||||
addTagAttribute(vers, RESOURCES_ANDROID_NAMESPACE, "targetSdkVersion",
|
return UNKNOWN_ERROR;
|
||||||
bundle->getTargetSdkVersion());
|
}
|
||||||
addTagAttribute(vers, RESOURCES_ANDROID_NAMESPACE, "maxSdkVersion",
|
if (!addTagAttribute(vers, RESOURCES_ANDROID_NAMESPACE, "targetSdkVersion",
|
||||||
bundle->getMaxSdkVersion());
|
bundle->getTargetSdkVersion(), errorOnFailedInsert)) {
|
||||||
|
return UNKNOWN_ERROR;
|
||||||
|
}
|
||||||
|
if (!addTagAttribute(vers, RESOURCES_ANDROID_NAMESPACE, "maxSdkVersion",
|
||||||
|
bundle->getMaxSdkVersion(), errorOnFailedInsert)) {
|
||||||
|
return UNKNOWN_ERROR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bundle->getDebugMode()) {
|
if (bundle->getDebugMode()) {
|
||||||
sp<XMLNode> application = root->getChildElement(String16(), String16("application"));
|
sp<XMLNode> application = root->getChildElement(String16(), String16("application"));
|
||||||
if (application != NULL) {
|
if (application != NULL) {
|
||||||
addTagAttribute(application, RESOURCES_ANDROID_NAMESPACE, "debuggable", "true");
|
if (!addTagAttribute(application, RESOURCES_ANDROID_NAMESPACE, "debuggable", "true",
|
||||||
|
errorOnFailedInsert)) {
|
||||||
|
return UNKNOWN_ERROR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user