diff --git a/tools/aapt2/integration-tests/AppOne/Android.mk b/tools/aapt2/integration-tests/AppOne/Android.mk
index 859cc8cbf4e53..bc40a6269382a 100644
--- a/tools/aapt2/integration-tests/AppOne/Android.mk
+++ b/tools/aapt2/integration-tests/AppOne/Android.mk
@@ -24,4 +24,5 @@ LOCAL_SRC_FILES := $(call all-java-files-under,src)
LOCAL_STATIC_ANDROID_LIBRARIES := \
AaptTestStaticLibOne \
AaptTestStaticLibTwo
+LOCAL_AAPT_FLAGS := --no-version-vectors
include $(BUILD_PACKAGE)
diff --git a/tools/aapt2/integration-tests/StaticLibTwo/res/drawable/vector.xml b/tools/aapt2/integration-tests/StaticLibTwo/res/drawable/vector.xml
new file mode 100644
index 0000000000000..dd5979f7e838d
--- /dev/null
+++ b/tools/aapt2/integration-tests/StaticLibTwo/res/drawable/vector.xml
@@ -0,0 +1,3 @@
+
+
diff --git a/tools/aapt2/link/Link.cpp b/tools/aapt2/link/Link.cpp
index b28415dc4a761..5003d96585258 100644
--- a/tools/aapt2/link/Link.cpp
+++ b/tools/aapt2/link/Link.cpp
@@ -278,6 +278,7 @@ static std::unique_ptr loadFileExportHeader(const Source& source,
struct ResourceFileFlattenerOptions {
bool noAutoVersion = false;
+ bool noVersionVectors = false;
bool keepRawValues = false;
bool doNotCompressAnything = false;
std::vector extensionsToNotCompress;
@@ -297,14 +298,13 @@ private:
io::IFile* fileToCopy;
std::unique_ptr xmlToFlatten;
std::string dstPath;
+ bool skipVersion = false;
};
uint32_t getCompressionFlags(const StringPiece& str);
- std::unique_ptr linkAndVersionXmlFile(const ResourceEntry* entry,
- const ResourceFile& fileDesc,
- io::IFile* file,
- ResourceTable* table);
+ bool linkAndVersionXmlFile(const ResourceEntry* entry, const ResourceFile& fileDesc,
+ io::IFile* file, ResourceTable* table, FileOperation* outFileOp);
ResourceFileFlattenerOptions mOptions;
IAaptContext* mContext;
@@ -324,11 +324,11 @@ uint32_t ResourceFileFlattener::getCompressionFlags(const StringPiece& str) {
return ArchiveEntry::kCompress;
}
-std::unique_ptr ResourceFileFlattener::linkAndVersionXmlFile(
- const ResourceEntry* entry,
- const ResourceFile& fileDesc,
- io::IFile* file,
- ResourceTable* table) {
+bool ResourceFileFlattener::linkAndVersionXmlFile(const ResourceEntry* entry,
+ const ResourceFile& fileDesc,
+ io::IFile* file,
+ ResourceTable* table,
+ FileOperation* outFileOp) {
const StringPiece srcPath = file->getSource().path;
if (mContext->verbose()) {
mContext->getDiagnostics()->note(DiagMessage() << "linking " << srcPath);
@@ -337,51 +337,67 @@ std::unique_ptr ResourceFileFlattener::linkAndVersionXmlFile(
std::unique_ptr data = file->openAsData();
if (!data) {
mContext->getDiagnostics()->error(DiagMessage(file->getSource()) << "failed to open file");
- return {};
+ return false;
}
- std::unique_ptr xmlRes;
if (util::stringEndsWith(srcPath, ".flat")) {
- xmlRes = loadBinaryXmlSkipFileExport(file->getSource(), data->data(), data->size(),
- mContext->getDiagnostics());
+ outFileOp->xmlToFlatten = loadBinaryXmlSkipFileExport(file->getSource(),
+ data->data(), data->size(),
+ mContext->getDiagnostics());
} else {
- xmlRes = xml::inflate(data->data(), data->size(), mContext->getDiagnostics(),
- file->getSource());
+ outFileOp->xmlToFlatten = xml::inflate(data->data(), data->size(),
+ mContext->getDiagnostics(),
+ file->getSource());
}
- if (!xmlRes) {
- return {};
+ if (!outFileOp->xmlToFlatten) {
+ return false;
}
// Copy the the file description header.
- xmlRes->file = fileDesc;
+ outFileOp->xmlToFlatten->file = fileDesc;
XmlReferenceLinker xmlLinker;
- if (!xmlLinker.consume(mContext, xmlRes.get())) {
- return {};
+ if (!xmlLinker.consume(mContext, outFileOp->xmlToFlatten.get())) {
+ return false;
}
- if (!proguard::collectProguardRules(xmlRes->file.source, xmlRes.get(), mKeepSet)) {
- return {};
+ if (!proguard::collectProguardRules(outFileOp->xmlToFlatten->file.source,
+ outFileOp->xmlToFlatten.get(), mKeepSet)) {
+ return false;
}
if (!mOptions.noAutoVersion) {
+ if (mOptions.noVersionVectors) {
+ // Skip this if it is a vector or animated-vector.
+ xml::Element* el = xml::findRootElement(outFileOp->xmlToFlatten.get());
+ if (el && el->namespaceUri.empty()) {
+ if (el->name == u"vector" || el->name == u"animated-vector") {
+ // We are NOT going to version this file.
+ outFileOp->skipVersion = true;
+ return true;
+ }
+ }
+ }
+
// Find the first SDK level used that is higher than this defined config and
// not superseded by a lower or equal SDK level resource.
for (int sdkLevel : xmlLinker.getSdkLevels()) {
- if (sdkLevel > xmlRes->file.config.sdkVersion) {
- if (!shouldGenerateVersionedResource(entry, xmlRes->file.config, sdkLevel)) {
+ if (sdkLevel > outFileOp->xmlToFlatten->file.config.sdkVersion) {
+ if (!shouldGenerateVersionedResource(entry, outFileOp->xmlToFlatten->file.config,
+ sdkLevel)) {
// If we shouldn't generate a versioned resource, stop checking.
break;
}
- ResourceFile versionedFileDesc = xmlRes->file;
+ ResourceFile versionedFileDesc = outFileOp->xmlToFlatten->file;
versionedFileDesc.config.sdkVersion = (uint16_t) sdkLevel;
if (mContext->verbose()) {
mContext->getDiagnostics()->note(DiagMessage(versionedFileDesc.source)
<< "auto-versioning resource from config '"
- << xmlRes->file.config << "' -> '"
+ << outFileOp->xmlToFlatten->file.config
+ << "' -> '"
<< versionedFileDesc.config << "'");
}
@@ -395,13 +411,13 @@ std::unique_ptr ResourceFileFlattener::linkAndVersionXmlFile(
file,
mContext->getDiagnostics());
if (!added) {
- return {};
+ return false;
}
break;
}
}
}
- return xmlRes;
+ return true;
}
/**
@@ -445,9 +461,7 @@ bool ResourceFileFlattener::flatten(ResourceTable* table, IArchiveWriter* archiv
fileDesc.config = configValue->config;
fileDesc.name = ResourceName(pkg->name, type->type, entry->name);
fileDesc.source = fileRef->getSource();
- fileOp.xmlToFlatten = linkAndVersionXmlFile(entry.get(), fileDesc,
- file, table);
- if (!fileOp.xmlToFlatten) {
+ if (!linkAndVersionXmlFile(entry.get(), fileDesc, file, table, &fileOp)) {
error = true;
continue;
}
@@ -477,7 +491,7 @@ bool ResourceFileFlattener::flatten(ResourceTable* table, IArchiveWriter* archiv
if (fileOp.xmlToFlatten) {
Maybe maxSdkLevel;
- if (!mOptions.noAutoVersion) {
+ if (!mOptions.noAutoVersion && !fileOp.skipVersion) {
maxSdkLevel = std::max(config.sdkVersion, 1u);
}
@@ -1215,6 +1229,7 @@ public:
fileFlattenerOptions.doNotCompressAnything = mOptions.doNotCompressAnything;
fileFlattenerOptions.extensionsToNotCompress = mOptions.extensionsToNotCompress;
fileFlattenerOptions.noAutoVersion = mOptions.noAutoVersion;
+ fileFlattenerOptions.noVersionVectors = mOptions.noVersionVectors;
ResourceFileFlattener fileFlattener(fileFlattenerOptions, mContext, &proguardKeepSet);
if (!fileFlattener.flatten(&mFinalTable, archiveWriter.get())) {
@@ -1222,7 +1237,7 @@ public:
return 1;
}
- if (!mOptions.staticLib && !mOptions.noAutoVersion) {
+ if (!mOptions.noAutoVersion) {
AutoVersioner versioner;
if (!versioner.consume(mContext, &mFinalTable)) {
mContext->getDiagnostics()->error(DiagMessage() << "failed versioning styles");
@@ -1505,6 +1520,12 @@ int link(const std::vector& args) {
options.tableSplitterOptions.preferredDensity = preferredDensityConfig.density;
}
+ // Turn off auto versioning for static-libs.
+ if (options.staticLib) {
+ options.noAutoVersion = true;
+ options.noVersionVectors = true;
+ }
+
LinkCommand cmd(&context, options);
return cmd.run(flags.getArgs());
}