diff options
author | Ryan Mitchell <rtmitchell@google.com> | 2020-02-26 12:45:39 -0800 |
---|---|---|
committer | Ryan Mitchell <rtmitchell@google.com> | 2020-02-26 21:35:47 +0000 |
commit | 60b74fb42fcb20b8b13937a846aeefb7e1b8c95e (patch) | |
tree | 11d2fdb1f4f6d240e93f34e90db6a664bddd5b8f /tools/aapt2 | |
parent | 58979d9557275d3780c6197803faeb6ba6e22d57 (diff) |
Add --rename-resources-package to aapt2
There is currently no way to change the package name encoded in the
resources table. This change adds a flag that controls rewriting the
package name encoded into the resources table. This flag does not
rewrite the package name in the manifest xml.
Bug: 147434671
Test: manual
Change-Id: I435ba07e29df0522c3a44cc5f2c460004a02d71c
Diffstat (limited to 'tools/aapt2')
-rw-r--r-- | tools/aapt2/cmd/Link.cpp | 7 | ||||
-rw-r--r-- | tools/aapt2/cmd/Link.h | 3 |
2 files changed, 8 insertions, 2 deletions
diff --git a/tools/aapt2/cmd/Link.cpp b/tools/aapt2/cmd/Link.cpp index 5b6935bafe71..bf886c2f893f 100644 --- a/tools/aapt2/cmd/Link.cpp +++ b/tools/aapt2/cmd/Link.cpp @@ -1766,9 +1766,12 @@ class Linker { return 1; } - // First extract the Package name without modifying it (via --rename-manifest-package). - if (Maybe<AppInfo> maybe_app_info = + // Determine the package name under which to merge resources. + if (options_.rename_resources_package) { + context_->SetCompilationPackage(options_.rename_resources_package.value()); + } else if (Maybe<AppInfo> maybe_app_info = ExtractAppInfoFromManifest(manifest_xml.get(), context_->GetDiagnostics())) { + // Extract the package name from the manifest ignoring the value of --rename-manifest-package. const AppInfo& app_info = maybe_app_info.value(); context_->SetCompilationPackage(app_info.package); } diff --git a/tools/aapt2/cmd/Link.h b/tools/aapt2/cmd/Link.h index 4722358be8f7..e7be43459e16 100644 --- a/tools/aapt2/cmd/Link.h +++ b/tools/aapt2/cmd/Link.h @@ -45,6 +45,7 @@ struct LinkOptions { bool auto_add_overlay = false; bool override_styles_instead_of_overlaying = false; OutputFormat output_format = OutputFormat::kApk; + Maybe<std::string> rename_resources_package; // Java/Proguard options. Maybe<std::string> generate_java_class_path; @@ -256,6 +257,8 @@ class LinkCommand : public Command { &options_.override_styles_instead_of_overlaying); AddOptionalFlag("--rename-manifest-package", "Renames the package in AndroidManifest.xml.", &options_.manifest_fixer_options.rename_manifest_package); + AddOptionalFlag("--rename-resources-package", "Renames the package in resources table", + &options_.rename_resources_package); AddOptionalFlag("--rename-instrumentation-target-package", "Changes the name of the target package for instrumentation. Most useful\n" "when used in conjunction with --rename-manifest-package.", |