AAPT2: Add dominator tree analysis and resource removal
Added dominator tree analysis of resource configurations for each
resource entry to allow deduping of resource entries if:
1. The configuration for the resource entry's value is dominated by
a configuration with an equivalent entry value.
2. All compatible configurations for the entry (those not in conflict
and unrelated by domination with the configuration for the entry's
value) have an equivalent entry value.
Bug: 30051199
Test: make libaapt2_tests && libaapt2_tests
Change-Id: I66468d3014a2d6097a94b039ac1028f9f461c7d3
diff --git a/tools/aapt2/link/Link.cpp b/tools/aapt2/link/Link.cpp
index c236394..b6b4b473 100644
--- a/tools/aapt2/link/Link.cpp
+++ b/tools/aapt2/link/Link.cpp
@@ -72,6 +72,7 @@
bool noAutoVersion = false;
bool noVersionVectors = false;
+ bool noResourceDeduping = false;
bool staticLib = false;
bool noStaticLibPackages = false;
bool generateNonFinalIds = false;
@@ -1505,6 +1506,14 @@
}
}
+ if (!mOptions.noResourceDeduping) {
+ ResourceDeduper deduper;
+ if (!deduper.consume(mContext, &mFinalTable)) {
+ mContext->getDiagnostics()->error(DiagMessage() << "failed deduping resources");
+ return 1;
+ }
+ }
+
proguard::KeepSet proguardKeepSet;
proguard::KeepSet proguardMainDexKeepSet;
@@ -1743,6 +1752,9 @@
"Disables automatic versioning of vector drawables. Use this only\n"
"when building with vector drawable support library",
&options.noVersionVectors)
+ .optionalSwitch("--no-resource-deduping", "Disables automatic deduping of resources with\n"
+ "identical values across compatible configurations.",
+ &options.noResourceDeduping)
.optionalSwitch("-x", "Legacy flag that specifies to use the package identifier 0x01",
&legacyXFlag)
.optionalSwitch("-z", "Require localization of strings marked 'suggested'",