From 940ae504984a15cb72dc40ad1e12adc7442b7f13 Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Wed, 26 Feb 2020 12:45:39 -0800 Subject: [PATCH] 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. (This is a cherry pick.) Bug: 147434671 Test: manual Merged-In: I435ba07e29df0522c3a44cc5f2c460004a02d71c Change-Id: I435ba07e29df0522c3a44cc5f2c460004a02d71c --- tools/aapt2/cmd/Link.cpp | 7 +++++-- 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 f354bb6102241..77e2a6bb21dea 100644 --- a/tools/aapt2/cmd/Link.cpp +++ b/tools/aapt2/cmd/Link.cpp @@ -1659,9 +1659,12 @@ class Linker { return 1; } - // First extract the Package name without modifying it (via --rename-manifest-package). - if (Maybe 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 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 be4d474ebdf36..e62e0a6b9f628 100644 --- a/tools/aapt2/cmd/Link.h +++ b/tools/aapt2/cmd/Link.h @@ -43,6 +43,7 @@ struct LinkOptions { bool output_to_directory = false; bool auto_add_overlay = false; OutputFormat output_format = OutputFormat::kApk; + Maybe rename_resources_package; // Java/Proguard options. Maybe generate_java_class_path; @@ -244,6 +245,8 @@ class LinkCommand : public Command { &options_.auto_add_overlay); 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.",