Chromium Code Reviews| 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..64a084316b5c41984dd2573446fb554cf11dcb87 100755 |
| --- a/build/android/gyp/process_resources.py |
| +++ b/build/android/gyp/process_resources.py |
| @@ -74,7 +74,12 @@ 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', |
|
agrieve
2016/12/14 18:16:02
nit: please indent same as other add_option calls
mlopatkin
2016/12/19 14:44:42
Done.
|
| + 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 +174,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 +453,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) |