summaryrefslogtreecommitdiff
path: root/tools/aapt2/cmd/Link.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/aapt2/cmd/Link.cpp')
-rw-r--r--tools/aapt2/cmd/Link.cpp37
1 files changed, 35 insertions, 2 deletions
diff --git a/tools/aapt2/cmd/Link.cpp b/tools/aapt2/cmd/Link.cpp
index db42e7cb3e02..1a2da7fbd000 100644
--- a/tools/aapt2/cmd/Link.cpp
+++ b/tools/aapt2/cmd/Link.cpp
@@ -17,6 +17,7 @@
#include <sys/stat.h>
#include <cinttypes>
+#include <algorithm>
#include <queue>
#include <unordered_map>
#include <vector>
@@ -111,6 +112,7 @@ struct LinkOptions {
// Static lib options.
bool no_static_lib_packages = false;
+ bool auto_namespace_static_lib = false;
// AndroidManifest.xml massaging options.
ManifestFixerOptions manifest_fixer_options;
@@ -135,6 +137,9 @@ struct LinkOptions {
// In order to work around this limitation, we allow the use of traditionally reserved
// resource IDs [those between 0x02 and 0x7E].
bool allow_reserved_package_id = false;
+
+ // Whether we should fail on definitions of a resource with conflicting visibility.
+ bool strict_visibility = false;
};
class LinkContext : public IAaptContext {
@@ -199,6 +204,14 @@ class LinkContext : public IAaptContext {
min_sdk_version_ = minSdk;
}
+ bool IsAutoNamespace() override {
+ return auto_namespace_;
+ }
+
+ void SetAutoNamespace(bool val) {
+ auto_namespace_ = val;
+ }
+
private:
DISALLOW_COPY_AND_ASSIGN(LinkContext);
@@ -210,6 +223,7 @@ class LinkContext : public IAaptContext {
SymbolTable symbols_;
bool verbose_ = false;
int min_sdk_version_ = 0;
+ bool auto_namespace_ = false;
};
// A custom delegate that generates compatible pre-O IDs for use with feature splits.
@@ -486,7 +500,7 @@ std::vector<std::unique_ptr<xml::XmlResource>> ResourceFileFlattener::LinkAndVer
return {};
}
- if (options_.update_proguard_spec && !proguard::CollectProguardRules(doc, keep_set_)) {
+ if (options_.update_proguard_spec && !proguard::CollectProguardRules(context_, doc, keep_set_)) {
return {};
}
@@ -1702,6 +1716,7 @@ class LinkCommand {
TableMergerOptions table_merger_options;
table_merger_options.auto_add_overlay = options_.auto_add_overlay;
+ table_merger_options.strict_visibility = options_.strict_visibility;
table_merger_ = util::make_unique<TableMerger>(context_, &final_table_, table_merger_options);
if (context_->IsVerbose()) {
@@ -2143,6 +2158,10 @@ int Link(const std::vector<StringPiece>& args, IDiagnostics* diagnostics) {
.OptionalSwitch("--no-static-lib-packages",
"Merge all library resources under the app's package.",
&options.no_static_lib_packages)
+ .OptionalSwitch("--auto-namespace-static-lib",
+ "Automatically namespace resource references when building a static\n"
+ "library.",
+ &options.auto_namespace_static_lib)
.OptionalSwitch("--non-final-ids",
"Generates R.java without the final modifier. This is implied when\n"
"--static-lib is specified.",
@@ -2186,6 +2205,8 @@ int Link(const std::vector<StringPiece>& args, IDiagnostics* diagnostics) {
&options.manifest_fixer_options.rename_instrumentation_target_package)
.OptionalFlagList("-0", "File extensions not to compress.",
&options.extensions_to_not_compress)
+ .OptionalSwitch("--no-compress", "Do not compress any resources.",
+ &options.do_not_compress_anything)
.OptionalSwitch("--warn-manifest-validation",
"Treat manifest validation errors as warnings.",
&options.manifest_fixer_options.warn_validation)
@@ -2198,7 +2219,10 @@ int Link(const std::vector<StringPiece>& args, IDiagnostics* diagnostics) {
.OptionalSwitch("--debug-mode",
"Inserts android:debuggable=\"true\" in to the application node of the\n"
"manifest, making the application debuggable even on production devices.",
- &options.manifest_fixer_options.debug_mode);
+ &options.manifest_fixer_options.debug_mode)
+ .OptionalSwitch("--strict-visibility",
+ "Do not allow overlays with different visibility levels.",
+ &options.strict_visibility);
if (!flags.Parse("aapt2 link", args, &std::cerr)) {
return 1;
@@ -2258,6 +2282,15 @@ int Link(const std::vector<StringPiece>& args, IDiagnostics* diagnostics) {
options.output_format = OutputFormat::kProto;
}
+ if (options.auto_namespace_static_lib) {
+ if (!static_lib) {
+ context.GetDiagnostics()->Error(
+ DiagMessage() << "--auto-namespace-static-lib can only be used with --static-lib");
+ return 1;
+ }
+ context.SetAutoNamespace(true);
+ }
+
if (package_id) {
if (context.GetPackageType() != PackageType::kApp) {
context.GetDiagnostics()->Error(