Rico Wind | 0ed24cc | 2018-03-23 07:16:35 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright (c) 2018, the R8 project authors. Please see the AUTHORS file |
| 3 | # for details. All rights reserved. Use of this source code is governed by a |
| 4 | # BSD-style license that can be found in the LICENSE file. |
| 5 | |
Søren Gjesse | cdae879 | 2018-12-12 09:02:43 +0100 | [diff] [blame] | 6 | import os |
Rico Wind | 0ed24cc | 2018-03-23 07:16:35 +0100 | [diff] [blame] | 7 | import subprocess |
| 8 | import utils |
| 9 | |
Christoffer Quist Adamsen | 41cbdca | 2019-04-12 08:52:03 +0200 | [diff] [blame] | 10 | def sign(unsigned_apk, signed_apk, keystore, quiet=False, logging=True): |
Christoffer Quist Adamsen | 1de3dde | 2019-01-24 13:17:46 +0100 | [diff] [blame] | 11 | utils.Print('Signing (ignore the warnings)', quiet=quiet) |
Rico Wind | 0ed24cc | 2018-03-23 07:16:35 +0100 | [diff] [blame] | 12 | cmd = ['zip', '-d', unsigned_apk, 'META-INF/*'] |
Christoffer Quist Adamsen | 41cbdca | 2019-04-12 08:52:03 +0200 | [diff] [blame] | 13 | utils.RunCmd(cmd, quiet=quiet, logging=logging) |
Rico Wind | 0ed24cc | 2018-03-23 07:16:35 +0100 | [diff] [blame] | 14 | cmd = [ |
| 15 | 'jarsigner', |
| 16 | '-sigalg', 'SHA1withRSA', |
| 17 | '-digestalg', 'SHA1', |
| 18 | '-keystore', keystore, |
| 19 | '-storepass', 'android', |
| 20 | '-signedjar', signed_apk, |
| 21 | unsigned_apk, |
| 22 | 'androiddebugkey' |
| 23 | ] |
Christoffer Quist Adamsen | 1de3dde | 2019-01-24 13:17:46 +0100 | [diff] [blame] | 24 | utils.RunCmd(cmd, quiet=quiet) |
Søren Gjesse | cdae879 | 2018-12-12 09:02:43 +0100 | [diff] [blame] | 25 | |
Christoffer Quist Adamsen | 3b6f106 | 2019-02-07 09:49:43 +0100 | [diff] [blame] | 26 | def sign_with_apksigner( |
Christoffer Quist Adamsen | 41cbdca | 2019-04-12 08:52:03 +0200 | [diff] [blame] | 27 | unsigned_apk, signed_apk, keystore, password='android', quiet=False, |
| 28 | logging=True): |
Søren Gjesse | cdae879 | 2018-12-12 09:02:43 +0100 | [diff] [blame] | 29 | cmd = [ |
Morten Krogh-Jespersen | 220e570 | 2019-02-27 12:57:01 +0100 | [diff] [blame] | 30 | os.path.join(utils.getAndroidBuildTools(), 'apksigner'), |
Søren Gjesse | cdae879 | 2018-12-12 09:02:43 +0100 | [diff] [blame] | 31 | 'sign', |
| 32 | '-v', |
| 33 | '--ks', keystore, |
| 34 | '--ks-pass', 'pass:' + password, |
| 35 | '--min-sdk-version', '19', |
| 36 | '--out', signed_apk, |
| 37 | unsigned_apk |
| 38 | ] |
Christoffer Quist Adamsen | 41cbdca | 2019-04-12 08:52:03 +0200 | [diff] [blame] | 39 | utils.RunCmd(cmd, quiet=quiet, logging=logging) |