学习途径:
- 官方命令行工具:https://developer.android.com/studio/command-line/apksigner
Usage
sign an apk
The syntax for signing an APK using the apksigner
tool is as follows:
|
|
When you sign an APK using the apksigner
tool, you must provide the signer’s private key and certificate. You can include this information in two different ways:
- Specify a Key Store file using the
--ks
option. - Specify the private key file and certificate file separately using the
--key
and--cert
options, respectively. The private key file must use thePKCS #8
format, and the certificate file must use theX.509
format.
Usually, you sign an APK using only one signer. In the event that you need to sign an APK using multiple signers, use the --next-signer
option to separate the set of general options to apply to each signer:
|
|
verify the signature of an apk
The syntax for confirming that an APK’s signature will be verified successfully on supported platforms is as follows:
|
|
Rotate signing keys
The syntax for rotating a signing certificate lineage, or a new sequence of signatures, is as follows:
|
|
Example
Sign an APK
Sign an APK using release.jks
, which is the only key in the KeyStore:
|
|
Sign an APK using a private key and certificate, stored as separate files:
|
|
Sign an APK using two keys:
|
|
Verify the signature of an APK
Check whether the APK’s signatures are expected to be confirmed as valid on all Android platforms that the APK supports:
|
|
Check whether the APK’s signatures are expected to be confirmed as valid on Android 4.0.3 (API level 15) and higher:
|
|
Rotate signing keys
Enable a signing certificate lineage that supports key rotation:
|
|
Rotate your signing keys again:
|
|