3 # Copyright 2013 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 """Signs and zipaligns APK.
15 from util import build_utils
17 def SignApk(key_path, key_name, key_passwd, unsigned_path, signed_path):
18 shutil.copy(unsigned_path, signed_path)
21 '-sigalg', 'MD5withRSA',
23 '-keystore', key_path,
24 '-storepass', key_passwd,
28 build_utils.CheckOutput(sign_cmd)
31 def AlignApk(zipalign_path, unaligned_path, final_path):
38 build_utils.CheckOutput(align_cmd)
42 parser = optparse.OptionParser()
44 parser.add_option('--zipalign-path', help='Path to the zipalign tool.')
45 parser.add_option('--unsigned-apk-path', help='Path to input unsigned APK.')
46 parser.add_option('--final-apk-path',
47 help='Path to output signed and aligned APK.')
48 parser.add_option('--key-path', help='Path to keystore for signing.')
49 parser.add_option('--key-passwd', help='Keystore password')
50 parser.add_option('--key-name', help='Keystore name')
51 parser.add_option('--stamp', help='Path to touch on success.')
53 options, _ = parser.parse_args()
55 with tempfile.NamedTemporaryFile() as intermediate_file:
56 signed_apk_path = intermediate_file.name
57 SignApk(options.key_path, options.key_name, options.key_passwd,
58 options.unsigned_apk_path, signed_apk_path)
59 AlignApk(options.zipalign_path, signed_apk_path, options.final_apk_path)
62 build_utils.Touch(options.stamp)
65 if __name__ == '__main__':