One, the APK is signed under the DOS command
First we need to synchronize the contents of the SRC directory in the Ionic project to Android and use the Ionic Cordova build android-release when using DOS commands. Instead of Ionic Cordova build Android. Such a signature-generated apk will work correctly on the phone, or a "signature check failed" prompt may appear.
We then need to locate our directory in the DOS command to execute under the Platforms/android directory in the Ionic project, or it may cause a failure to install properly.
A total of 3 tools (commands) are required to sign the APK under a DOS command, Keytool, Jarsigner, and Zipalign, with an introduction to these 3 tools:
Keytool: Generate a digital certificate, which is a key, is a file with a. keystore extension; Jarsigner: Use a digital certificate to sign the APK file zipalign: Optimize the signed apk to improve the efficiency of interacting with the Android system (Android SDK1.6 and later versions start with this tool) the execution order of the 3 tools is shown above. Usually we develop our own application, all using the same signature, that is, using the same digital certificate, which means that if you first do the APK signature, the above 3 tools will be used, but if you already have a digital certificate, then in the other apk signature, You just need to use the Jarsigner and zipalign tools. The following is the default path for these 3 tools Keytool: Located in the bin directory of the JDK installation path Jarsigner: Located in the bin directory of the JDK installation path zipalign: In the tools directory of the SDK installation path for ease of use, we can put these 3 jobs Path is added to the environment variable path, but typically we add the JDK and SDK to the path by configuring the environment variable. Extension: From the above path can be seen, Keytool and jarsigner These two tools are JDK, that is, the generation of digital certificates and file signing is not a patent of Android, In addition to the literal understanding of Jarsigner can also be guessed that the tool is mainly used to sign the jar file. Here's how to sign the APK under DOS commands: 1. Generate a digital certificate using the Keytool tool
Keytool-genkey-v-keystore myself.keystore-alias myself.keystore-keyalg rsa-validity 20000
Description: Keytool is the tool name,-genkey means the operation to generate a digital certificate, and-V to print out the details of the generated certificate, displayed in a DOS window-keystore myself.keystore indicates the file name of the generated digital certificate is " Myself.keystore "-alias Myself.keystore means that the certificate alias is" Myself.keystore ", of course, can not be the same as the above file name-keyalg RSA means the algorithm used to generate the key file is RSA;- Validity 20000 indicates that the certificate is valid for 20,000 days, which means that after 20,000 days the certificate is invalidated when you generate a digital certificate file from the command above, you are prompted to enter some information, including the certificate's password, and whether it will be determined. Fill in the Y, enter, the example is as follows: (Note: I enter the password in the WIN10 system will not be displayed in the DOS system, but it is input, do not suspect that your keyboard is out of order) after the command is completed, the Myself.keystore file is generated in the current directory.
If you want to see information about the signature, enter it on the DOS command line:
Keytool-list-keystore "Myself.keystore" Enter the KeyStore password you set
Note to fill in the directory where the KeyStore is located, or to populate the full path of KeyStore
2. Sign the APK with the Jarsigner tool
2.1 jdk1.6 Version command:
Jarsigner-verbose-keystore Myself.keystore-signedjar demo_signed.apk demo.apk myself.keystore
Jarsigner is the tool name,-verbose means to print the details of the signature process, displayed in a DOS window-keystore Myself.keystore represents the location of the digital certificate used by the signature, there is no write path, which means in the current directory If you do not need to add a path under the current folder, the examples are:
Jarsigner.exe-verbose-keystore d:\aa\myself.keystore-storepass Android-signedjar d:\aa\demo_signed.apk d:\aa\ demo.apk Myself.keystore
Signedjar demo_signed.apk demo.apk represents the signature of the demo.apk file, after which the file name is called demo_signed.apk The last Myself.keystore represents the alias of the certificate, and the name after the-alias parameter corresponding to the digital certificate
2.2 jdk1.8 Command: (jdk1.8 algorithm has changed, need to specify-SIGALG and-digestalg)
Jarsigner-verbose-sigalg sha1withrsa-digestalg sha1-keystore myself.keystore-storepass Android-signedjar Demo_signe d.apk demo.apk Myself.keystore
Note here that-storepass Android is our direct output of the KeyStore file password, Android is I set the password, here need to change to your own. If you do not want to directly write up can also be removed, after the command will remind you to enter the password. The rest of the orders have been spoken in 2.1.
3. Use the Zipalign tool to optimize an already signed apk (not required but recommended)
Zipalign-v 4 demo_signed.apk demo_signed_aligned.apk
Description: Zipalign is the tool name, and-V indicates that detailed optimization information is printed in the DOS window; demo_signed.apk demo_signed_aligned.apk indicates that the signature file has been Demo_ SIGNED.APK is optimized, the optimized file name is demo_signed_aligned.apk Description: If your previous program is using the default signature method (that is, debug signature), once the new signature application will not overwrite the installation, the original program must be uninstalled, To install the
Above reference: http://www.cnblogs.com/share123/p/5900583.html
second, for the APK signature may encounter problems as follows:
1. The jar cannot be signed when it is being re-signedTip "Jarsigner: The jar could not be signed: Java.util.zip.ZipException:invalid entry compressed size (expected 7502 but got 6912 bytes)", As shown in figure
Workaround: Change the apk suffix you want to re-sign to zip, open and delete the Meta-inf directory, then change it to the apk suffix, and finally sign the APK.