OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # |
| 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. |
| 6 |
| 7 """Process Android library resources to generate R.java and crunched images.""" |
| 8 |
| 9 import optparse |
| 10 import os |
| 11 import subprocess |
| 12 |
| 13 |
| 14 BUILD_ANDROID_DIR = os.path.dirname(__file__) |
| 15 |
| 16 |
| 17 def ParseArgs(): |
| 18 """Parses command line options. |
| 19 |
| 20 Returns: |
| 21 An options object as from optparse.OptionsParser.parse_args() |
| 22 """ |
| 23 parser = optparse.OptionParser() |
| 24 parser.add_option('--android-sdk', help='path to the Android SDK folder') |
| 25 parser.add_option('--android-sdk-tools', |
| 26 help='path to the Android SDK platform tools folder') |
| 27 parser.add_option('--R-package', help='Java package for generated R.java') |
| 28 parser.add_option('--R-dir', help='directory to hold generated R.java') |
| 29 parser.add_option('--res-dir', help='directory containing resources') |
| 30 parser.add_option('--crunched-res-dir', |
| 31 help='directory to hold crunched resources') |
| 32 (options, args) = parser.parse_args() |
| 33 |
| 34 if args: |
| 35 parser.error('No positional arguments should be given.') |
| 36 |
| 37 # Check that required options have been provided. |
| 38 required_options = ('android_sdk', 'android_sdk_tools', 'R_package', |
| 39 'R_dir', 'res_dir', 'crunched_res_dir') |
| 40 for option_name in required_options: |
| 41 if getattr(options, option_name) is None: |
| 42 parser.error('--%s is required' % option_name.replace('_', '-')) |
| 43 |
| 44 return options |
| 45 |
| 46 |
| 47 def main(): |
| 48 options = ParseArgs() |
| 49 android_jar = os.path.join(options.android_sdk, 'android.jar') |
| 50 aapt = os.path.join(options.android_sdk_tools, 'aapt') |
| 51 dummy_manifest = os.path.join(BUILD_ANDROID_DIR, 'AndroidManifest.xml') |
| 52 |
| 53 # Generate R.java. This R.java contains non-final constants and is used only |
| 54 # while compiling the library jar (e.g. chromium_content.jar). When building |
| 55 # an apk, a new R.java file with the correct resource -> ID mappings will be |
| 56 # generated by merging the resources from all libraries and the main apk |
| 57 # project. |
| 58 subprocess.check_call([aapt, |
| 59 'package', |
| 60 '-m', |
| 61 '--non-constant-id', |
| 62 '--custom-package', options.R_package, |
| 63 '-M', dummy_manifest, |
| 64 '-S', options.res_dir, |
| 65 '-I', android_jar, |
| 66 '-J', options.R_dir]) |
| 67 |
| 68 # Crunch image resources. This shrinks png files and is necessary for 9-patch |
| 69 # images to display correctly. |
| 70 subprocess.check_call([aapt, |
| 71 'crunch', |
| 72 '-S', options.res_dir, |
| 73 '-C', options.crunched_res_dir]) |
| 74 |
| 75 |
| 76 if __name__ == '__main__': |
| 77 main() |
OLD | NEW |