AAPT2: Add version collapsing
When an app specifies (or imports) resources with various
configurations for different SDK versions, specifying
a minSdk will make many of those resources unreachable.
Version collapsing will prune out the resources specified
for SDK versions less than the minSdk.
If, however, there is no exact matching resource for the
minSdk version, the next smallest SDK version is kept.
Change-Id: Ic7bcab6c59d65c97c67c8767358abb57cdec60a4
diff --git a/tools/aapt2/test/Builders.h b/tools/aapt2/test/Builders.h
index 8eb4bc8..fb1d8f8 100644
--- a/tools/aapt2/test/Builders.h
+++ b/tools/aapt2/test/Builders.h
@@ -50,6 +50,11 @@
return addValue(name, id, util::make_unique<Id>());
}
+ ResourceTableBuilder& addSimple(const StringPiece16& name, const ConfigDescription& config,
+ const ResourceId id = {}) {
+ return addValue(name, config, id, util::make_unique<Id>());
+ }
+
ResourceTableBuilder& addReference(const StringPiece16& name, const StringPiece16& ref) {
return addReference(name, {}, ref);
}
@@ -70,7 +75,7 @@
ResourceTableBuilder& addString(const StringPiece16& name, const ResourceId id,
const ConfigDescription& config, const StringPiece16& str) {
- return addValue(name, id, config,
+ return addValue(name, config, id,
util::make_unique<String>(mTable->stringPool.makeRef(str)));
}
@@ -86,7 +91,7 @@
ResourceTableBuilder& addFileReference(const StringPiece16& name, const StringPiece16& path,
const ConfigDescription& config) {
- return addValue(name, {}, config,
+ return addValue(name, config, {},
util::make_unique<FileReference>(mTable->stringPool.makeRef(path)));
}
@@ -96,13 +101,12 @@
}
ResourceTableBuilder& addValue(const StringPiece16& name, const ResourceId id,
- std::unique_ptr<Value> value) {
- return addValue(name, id, {}, std::move(value));
+ std::unique_ptr<Value> value) {
+ return addValue(name, {}, id, std::move(value));
}
- ResourceTableBuilder& addValue(const StringPiece16& name, const ResourceId id,
- const ConfigDescription& config,
- std::unique_ptr<Value> value) {
+ ResourceTableBuilder& addValue(const StringPiece16& name, const ConfigDescription& config,
+ const ResourceId id, std::unique_ptr<Value> value) {
ResourceName resName = parseNameOrDie(name);
bool result = mTable->addResourceAllowMangled(resName, id, config, std::string(),
std::move(value), &mDiagnostics);
diff --git a/tools/aapt2/test/Context.h b/tools/aapt2/test/Context.h
index 96752d3..36f568b 100644
--- a/tools/aapt2/test/Context.h
+++ b/tools/aapt2/test/Context.h
@@ -58,17 +58,19 @@
return false;
}
+ int getMinSdkVersion() override {
+ return mMinSdkVersion;
+ }
+
private:
friend class ContextBuilder;
- Context() : mNameMangler({}) {
- }
-
Maybe<std::u16string> mCompilationPackage;
Maybe<uint8_t> mPackageId;
StdErrDiagnostics mDiagnostics;
SymbolTable mSymbols;
- NameMangler mNameMangler;
+ NameMangler mNameMangler = NameMangler({});
+ int mMinSdkVersion = 0;
};
class ContextBuilder {
@@ -96,6 +98,11 @@
return *this;
}
+ ContextBuilder& setMinSdkVersion(int minSdk) {
+ mContext->mMinSdkVersion = minSdk;
+ return *this;
+ }
+
std::unique_ptr<Context> build() {
return std::move(mContext);
}