From 2b7e847ac9f3dc7959e27cee86c9d61d11ceacbf Mon Sep 17 00:00:00 2001 From: Ryan Mitchell Date: Wed, 6 May 2020 11:26:48 -0700 Subject: Do not rename R.java package When the --rename-resources-package flag is used, only rename the package name within the resources.arsc. Generate the R.java under the package name defined by the manifest unless --custom-package is used. Bug: 147434671 Test: manual Change-Id: Id9d10e16f32533da1b67ab72ac846791526e7a76 --- tools/aapt2/cmd/Link.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'tools/aapt2/cmd') diff --git a/tools/aapt2/cmd/Link.cpp b/tools/aapt2/cmd/Link.cpp index bf886c2f893f..3a3fb2826b74 100644 --- a/tools/aapt2/cmd/Link.cpp +++ b/tools/aapt2/cmd/Link.cpp @@ -1766,16 +1766,23 @@ class Linker { return 1; } - // 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 = + // First extract the Package name without modifying it (via --rename-manifest-package). + 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); } + // Determine the package name under which to merge resources. + if (options_.rename_resources_package) { + if (!options_.custom_java_package) { + // Generate the R.java under the original package name instead of the package name specified + // through --rename-resources-package. + options_.custom_java_package = context_->GetCompilationPackage(); + } + context_->SetCompilationPackage(options_.rename_resources_package.value()); + } + // Now that the compilation package is set, load the dependencies. This will also extract // the Android framework's versionCode and versionName, if they exist. if (!LoadSymbolsFromIncludePaths()) { -- cgit v1.2.3-59-g8ed1b