diff --git a/tools/aapt/Bundle.h b/tools/aapt/Bundle.h index e7cde749e9baf..3dae917435c22 100644 --- a/tools/aapt/Bundle.h +++ b/tools/aapt/Bundle.h @@ -54,7 +54,7 @@ public: mWantUTF16(false), mValues(false), mIncludeMetaData(false), mCompressionMethod(0), mJunkPath(false), mOutputAPKFile(NULL), mManifestPackageNameOverride(NULL), mInstrumentationPackageNameOverride(NULL), - mAutoAddOverlay(false), mGenDependencies(false), + mAutoAddOverlay(false), mGenDependencies(false), mNoVersionVectors(false), mCrunchedOutputDir(NULL), mProguardFile(NULL), mAndroidManifestFile(NULL), mPublicOutputFile(NULL), mRClassDir(NULL), mResourceIntermediatesDir(NULL), mManifestMinSdkVersion(NULL), @@ -203,6 +203,8 @@ public: void setSingleCrunchOutputFile(const char* val) { mSingleCrunchOutputFile = val; } bool getBuildSharedLibrary() const { return mBuildSharedLibrary; } void setBuildSharedLibrary(bool val) { mBuildSharedLibrary = val; } + void setNoVersionVectors(bool val) { mNoVersionVectors = val; } + bool getNoVersionVectors() const { return mNoVersionVectors; } /* * Set and get the file specification. @@ -282,6 +284,7 @@ private: const char* mInstrumentationPackageNameOverride; bool mAutoAddOverlay; bool mGenDependencies; + bool mNoVersionVectors; const char* mCrunchedOutputDir; const char* mProguardFile; const char* mAndroidManifestFile; diff --git a/tools/aapt/Main.cpp b/tools/aapt/Main.cpp index 8b416aa82fdb0..7dee585fa7bed 100644 --- a/tools/aapt/Main.cpp +++ b/tools/aapt/Main.cpp @@ -211,7 +211,9 @@ void usage(void) " specified folder.\n" " --ignore-assets\n" " Assets to be ignored. Default pattern is:\n" - " %s\n", + " %s\n" + " --no-version-vectors\n" + " Do not automatically generate versioned copies of vector XML resources.\n", gDefaultIgnoreAssets); } @@ -673,6 +675,8 @@ int main(int argc, char* const argv[]) gUserIgnoreAssets = argv[0]; } else if (strcmp(cp, "-pseudo-localize") == 0) { bundle.setPseudolocalize(PSEUDO_ACCENTED | PSEUDO_BIDI); + } else if (strcmp(cp, "-no-version-vectors") == 0) { + bundle.setNoVersionVectors(true); } else { fprintf(stderr, "ERROR: Unknown option '-%s'\n", cp); wantUsage = true; diff --git a/tools/aapt/ResourceTable.cpp b/tools/aapt/ResourceTable.cpp index c5fccbf02914e..3b146da630d82 100644 --- a/tools/aapt/ResourceTable.cpp +++ b/tools/aapt/ResourceTable.cpp @@ -4611,6 +4611,9 @@ status_t ResourceTable::modifyForCompat(const Bundle* bundle, const String16& resourceName, const sp& target, const sp& root) { + const String16 vector16("vector"); + const String16 animatedVector16("animated-vector"); + const int minSdk = getMinSdkVersion(bundle); if (minSdk >= SDK_LOLLIPOP_MR1) { // Lollipop MR1 and up handles public attributes differently, no @@ -4620,8 +4623,8 @@ status_t ResourceTable::modifyForCompat(const Bundle* bundle, const ConfigDescription config(target->getGroupEntry().toParams()); if (target->getResourceType() == "" || config.sdkVersion >= SDK_LOLLIPOP_MR1) { - // Skip resources that have no type (AndroidManifest.xml) or are already version qualified with v21 - // or higher. + // Skip resources that have no type (AndroidManifest.xml) or are already version qualified + // with v21 or higher. return NO_ERROR; } @@ -4635,6 +4638,12 @@ status_t ResourceTable::modifyForCompat(const Bundle* bundle, sp node = nodesToVisit.top(); nodesToVisit.pop(); + if (bundle->getNoVersionVectors() && (node->getElementName() == vector16 || + node->getElementName() == animatedVector16)) { + // We were told not to version vector tags, so skip the children here. + continue; + } + const Vector& attrs = node->getAttributes(); for (size_t i = 0; i < attrs.size(); i++) { const XMLNode::attribute_entry& attr = attrs[i];