Sign an APK using the command line

1. Create keystore library

Command line input:

keytool -genkeypair -alias crazyit.keystore -keyalg RSA -validity 400 -keystore crazyit.keystore

enter

Enter the keystore password, enter

Enter the password (ie password) again, enter

first and last name, enter

unit name, enter

organization name, enter

city, enter

province, enter

Country code (zh),enter

keystore password, enter

-genkeypair: Specify the generation of digital certificate
-alias: Specify the alias for generating the digital certificate
-keyalg: Specify the algorithm for generating the digital certificate, using the RSA algorithm
-validity: Specify the validity period of the generated digital certificate
-keystore: Specify the storage path of the generated digital certificate

2. Generate unsigned Apk installation package

Right-click the Android project in Eclipse -> Android Tools -> Export Onsigned Application Package..., Eclipse pops up a save file dialog box, click Finish.

3. Use the jarsigner command to sign the unsigned APK installation package

Enter the command in the command line window:

jarsigner -verbose -keystore crazyit keystore -signedjar HelloWorld_crazyit.apk HelloWorld.apk crazyit.keystore

enter, which will ask the user to enter a password

-verbose: Specifies to generate detailed output
-keystore: Specifies the storage path of the digital certificate
-signedjar: The three parameters of this option are the signed APK package, the unsigned APK package, and the alias of the digital certificate

4. Use the zipalign.exe tool to optimize the APK installation package

zippalign.exe is a file organization tool that comes with android. It is used to optimize the apk installation package to improve the interaction efficiency between the android application and the system, and improve the running speed of the application. Command line input:

zipalign -f -v 4 HelloWord_crazyit.apk HelloWorld_crazyit_zip.apk

-f: Specifies to force overwriting of existing files
-v: Specifies to generate detailed output
4: Specifies the number of bytes on which the file is sorted, usually specified as 4, that is, sorting based on 32 bits
HelloWorld_crazyit.apk and HelloWorld_crazyit_zip.apk are specified respectively Apk before sorting and apk after sorting

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325773969&siteId=291194637