| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2014 The Chromium Authors. All rights reserved. | 3 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 # pylint: disable=C0301 | 7 # pylint: disable=C0301 |
| 8 """Package resources into an apk. | 8 """Package resources into an apk. |
| 9 | 9 |
| 10 See https://android.googlesource.com/platform/tools/base/+/master/legacy/ant-tas
ks/src/main/java/com/android/ant/AaptExecTask.java | 10 See https://android.googlesource.com/platform/tools/base/+/master/legacy/ant-tas
ks/src/main/java/com/android/ant/AaptExecTask.java |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 def ParseArgs(): | 65 def ParseArgs(): |
| 66 """Parses command line options. | 66 """Parses command line options. |
| 67 | 67 |
| 68 Returns: | 68 Returns: |
| 69 An options object as from optparse.OptionsParser.parse_args() | 69 An options object as from optparse.OptionsParser.parse_args() |
| 70 """ | 70 """ |
| 71 parser = optparse.OptionParser() | 71 parser = optparse.OptionParser() |
| 72 build_utils.AddDepfileOption(parser) | 72 build_utils.AddDepfileOption(parser) |
| 73 parser.add_option('--android-sdk', help='path to the Android SDK folder') | 73 parser.add_option('--android-sdk', help='path to the Android SDK folder') |
| 74 parser.add_option('--android-sdk-tools', | 74 parser.add_option('--aapt-path', |
| 75 help='path to the Android SDK build tools folder') | 75 help='path to the Android aapt tool') |
| 76 | 76 |
| 77 parser.add_option('--configuration-name', | 77 parser.add_option('--configuration-name', |
| 78 help='Gyp\'s configuration name (Debug or Release).') | 78 help='Gyp\'s configuration name (Debug or Release).') |
| 79 | 79 |
| 80 parser.add_option('--android-manifest', help='AndroidManifest.xml path') | 80 parser.add_option('--android-manifest', help='AndroidManifest.xml path') |
| 81 parser.add_option('--version-code', help='Version code for apk.') | 81 parser.add_option('--version-code', help='Version code for apk.') |
| 82 parser.add_option('--version-name', help='Version name for apk.') | 82 parser.add_option('--version-name', help='Version name for apk.') |
| 83 parser.add_option( | 83 parser.add_option( |
| 84 '--shared-resources', | 84 '--shared-resources', |
| 85 action='store_true', | 85 action='store_true', |
| (...skipping 12 matching lines...) Expand all Loading... |
| 98 | 98 |
| 99 parser.add_option('--apk-path', | 99 parser.add_option('--apk-path', |
| 100 help='Path to output (partial) apk.') | 100 help='Path to output (partial) apk.') |
| 101 | 101 |
| 102 (options, args) = parser.parse_args() | 102 (options, args) = parser.parse_args() |
| 103 | 103 |
| 104 if args: | 104 if args: |
| 105 parser.error('No positional arguments should be given.') | 105 parser.error('No positional arguments should be given.') |
| 106 | 106 |
| 107 # Check that required options have been provided. | 107 # Check that required options have been provided. |
| 108 required_options = ('android_sdk', 'android_sdk_tools', 'configuration_name', | 108 required_options = ('android_sdk', 'aapt_path', 'configuration_name', |
| 109 'android_manifest', 'version_code', 'version_name', | 109 'android_manifest', 'version_code', 'version_name', |
| 110 'apk_path') | 110 'apk_path') |
| 111 | 111 |
| 112 build_utils.CheckOptions(options, parser, required=required_options) | 112 build_utils.CheckOptions(options, parser, required=required_options) |
| 113 | 113 |
| 114 return options | 114 return options |
| 115 | 115 |
| 116 | 116 |
| 117 def MoveImagesToNonMdpiFolders(res_root): | 117 def MoveImagesToNonMdpiFolders(res_root): |
| 118 """Move images from drawable-*-mdpi-* folders to drawable-* folders. | 118 """Move images from drawable-*-mdpi-* folders to drawable-* folders. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 if trigger in name and not 'mipmap-' in name: | 180 if trigger in name and not 'mipmap-' in name: |
| 181 raise Exception(('Found density in main apk that should have been ' + | 181 raise Exception(('Found density in main apk that should have been ' + |
| 182 'put into a split: %s\nYou need to update ' + | 182 'put into a split: %s\nYou need to update ' + |
| 183 'package_resources.py to include this new ' + | 183 'package_resources.py to include this new ' + |
| 184 'config.') % name) | 184 'config.') % name) |
| 185 | 185 |
| 186 | 186 |
| 187 def main(): | 187 def main(): |
| 188 options = ParseArgs() | 188 options = ParseArgs() |
| 189 android_jar = os.path.join(options.android_sdk, 'android.jar') | 189 android_jar = os.path.join(options.android_sdk, 'android.jar') |
| 190 aapt = os.path.join(options.android_sdk_tools, 'aapt') | 190 aapt = options.aapt_path |
| 191 | 191 |
| 192 with build_utils.TempDir() as temp_dir: | 192 with build_utils.TempDir() as temp_dir: |
| 193 package_command = [aapt, | 193 package_command = [aapt, |
| 194 'package', | 194 'package', |
| 195 '--version-code', options.version_code, | 195 '--version-code', options.version_code, |
| 196 '--version-name', options.version_name, | 196 '--version-name', options.version_name, |
| 197 '-M', options.android_manifest, | 197 '-M', options.android_manifest, |
| 198 '--no-crunch', | 198 '--no-crunch', |
| 199 '-f', | 199 '-f', |
| 200 '--auto-add-overlay', | 200 '--auto-add-overlay', |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 RenameDensitySplits(options.apk_path) | 236 RenameDensitySplits(options.apk_path) |
| 237 | 237 |
| 238 if options.depfile: | 238 if options.depfile: |
| 239 build_utils.WriteDepfile( | 239 build_utils.WriteDepfile( |
| 240 options.depfile, | 240 options.depfile, |
| 241 build_utils.GetPythonDependencies()) | 241 build_utils.GetPythonDependencies()) |
| 242 | 242 |
| 243 | 243 |
| 244 if __name__ == '__main__': | 244 if __name__ == '__main__': |
| 245 main() | 245 main() |
| OLD | NEW |