Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(891)

Unified Diff: build/android/gyp/process_resources.py

Issue 2570313002: Use R.txt from AAR to generate R.java for it when building APK. (Closed)
Patch Set: Added workaround for aars with empty R.txt and no resources. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/gyp/aar.py ('k') | build/config/android/internal_rules.gni » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/gyp/process_resources.py
diff --git a/build/android/gyp/process_resources.py b/build/android/gyp/process_resources.py
index 2d4638f8d81f77dca0dacb705e4ca9fbdc5959cf..0f68866647b26d6bf1877f0c3486bcb829f034f6 100755
--- a/build/android/gyp/process_resources.py
+++ b/build/android/gyp/process_resources.py
@@ -74,7 +74,11 @@ def _ParseArgs(args):
parser.add_option('--srcjar-out',
help='Path to srcjar to contain generated R.java.')
parser.add_option('--r-text-out',
- help='Path to store the R.txt file generated by appt.')
+ help='Path to store the generated R.txt file.')
+ parser.add_option('--r-text-in',
+ help='Path to pre-existing R.txt for these resources. '
+ 'Resource names from it will be used to generate R.java '
+ 'instead of aapt-generated R.txt.')
parser.add_option('--proguard-file',
help='Path to proguard.txt generated file')
@@ -169,8 +173,24 @@ def CreateRJavaFiles(srcjar_dir, main_r_txt_file, packages, r_txt_files,
# figure out which entries belong to them, but use the values from the
# main R.txt file.
for entry in _ParseTextSymbolsFile(r_txt_file):
- entry = all_resources[(entry.resource_type, entry.name)]
- resources_by_type[entry.resource_type].append(entry)
+ entry = all_resources.get((entry.resource_type, entry.name))
+ # For most cases missing entry here is an error. It means that some
+ # library claims to have or depend on a resource that isn't included into
+ # the APK. There is one notable exception: Google Play Services (GMS).
+ # GMS is shipped as a bunch of AARs. One of them - basement - contains
+ # R.txt with ids of all resources, but most of the resources are in the
+ # other AARs. However, all other AARs reference their resources via
+ # basement's R.java so the latter must contain all ids that are in its
+ # R.txt. Most targets depend on only a subset of GMS AARs so some
+ # resources are missing, which is okay because the code that references
+ # them is missing too. We can't get an id for a resource that isn't here
+ # so the only solution is to skip the resource entry entirely.
+ #
+ # We can verify that all entries referenced in the code were generated
+ # correctly by running Proguard on the APK: it will report missing
+ # fields.
+ if entry:
+ resources_by_type[entry.resource_type].append(entry)
for package, resources_by_type in resources_by_package.iteritems():
package_r_java_dir = os.path.join(srcjar_dir, *package.split('.'))
@@ -432,6 +452,12 @@ def _OnStaleMd5(options):
build_utils.Touch(r_txt_path)
if not options.include_all_resources:
+ # --include-all-resources can only be specified for generating final R
+ # classes for APK. It makes no sense for APK to have pre-generated R.txt
+ # though, because aapt-generated already lists all available resources.
+ if options.r_text_in:
+ r_txt_path = options.r_text_in
+
packages = list(options.extra_res_packages)
r_txt_files = list(options.extra_r_text_files)
« no previous file with comments | « build/android/gyp/aar.py ('k') | build/config/android/internal_rules.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698