- From http://www.cnblogs.com/xiwix/archive/2012/04/15/2447910.html
- This article focuses on the theoretical knowledge of Android application signatures, including: What is a signature, why to sign an application, how to sign an application, and so on.
- 1, what is the signature?
If this problem is not in the Android development to ask, if it is placed in an ordinary section, I think we all know the meaning of the signature. It is often that some of life's commonly used terminology in the field of computer science, people began to confuse. What does the computer do, or what the programming language does, not simulate reality as much as possible? So, the signature in the computer and the signature in life are the same in nature, and the function that it plays is the same!
Let's take a look at the signature in real life. Signing means writing your name on paper or elsewhere, or marking it somewhere as a unique sign of yourself, and when someone sees the signature, he will know that it's about you, not someone else.
- 2. Why do I need to sign the Android app?
If you can only answer this question in a simple sentence, I will say, "This is what the Android system requires."
Android requires every Android app to be digitally signed to install into the system, meaning that if an Android app is not digitally signed, there is no way to install it! Android uses digital signatures to identify the author of an application and establish a trust relationship between applications, not to determine which applications the end user can install. This digital signature is done by the author of the application and does not require an authoritative digital certificate signing Authority authentication, which is only used to make the application package self-certified.
- 3. Why do I develop Android apps that do not have any signatures to run on the emulator and phone?
You do not have to sign the Android app and it doesn't mean that the Android app is not signed. To facilitate our development of the debug program, ADT automatically uses the debug key to sign the application. Debug key? Where is it? The Debug key is a file named Debug.keystore and its location:
system drive letter: \documents and Settings\liufeng\.android\debug.keystore
- "Liufeng" corresponds to your own Windows operating system user name, what, is not already found it. This means that if we want to have our own signature, instead of having ADT sign it for us, we also have a key file (*.keystore) that belongs to you.
- 4. Android App signing step
- 1) Preparatory work
APK signature work can be done in two ways:
1) Complete the APK signature via the graphical interface provided by ADT;
- 2) Full DOS command to complete the APK signature
I prefer the 2nd way, So the following will explain how to complete the APK signature by command. The
to the APK signed a total of 3 tools, or 3 commands, respectively: Keytool, Jarsigner and Zipalign, the following is a brief introduction to these 3 tools:
1) Keytool: Generate a digital certificate, which is a key, That is, the type of file with the. keystore extension mentioned above;
- 2) Jarsigner: Use digital certificate to sign APK file;
3) Zipalign: Optimize the signature apk to improve the efficiency of interacting with Android (Android SDK1.6 version starts with this tool)
The effects of these 3 tools can also be seen in the order in which these 3 tools are used. Usually all of the applications we develop ourselves use the same signature, that is, using the same digital certificate, which means: If you are signing the Android app for the first time, the 3 tools above will be used, but if you already have a digital certificate and then you sign the other apk later, You just need to use Jarsigner and zipalign to do it.
To facilitate the use of the above 3 commands, you first need to add the paths of the above 3 tools to the environment variable path (I said it is for ease of use, did not say that this must be done). How to configure the environment variable is not explained here, here you need to say the default path of the 3 tools:
1) Keytool: The tool is located in the bin directory of the JDK installation path;
- 2) Jarsigner: The tool is located in the bin directory of the JDK installation path;
3) Zipalign: The tool is located in the Android-sdk-windows\tools\ directory
- It is not known whether people notice that the Keytool and Jarsigner two tools are the JDK, which means that the generation of digital certificates and file signatures is not a patent for Android, and it is also literally understood that the tool is primarily used to sign the jar file, Jarsigner.
- 2) generate an unsigned apk file
Now that we have to sign the apk ourselves, we no longer need the ADT to sign it for us by default. How do I get an unsigned apk file? open Eclipse, right-click on the Android project name, select "Android Tools"-"Export Unsigned application Package ..." and select a storage location to save. This will get an unsigned apk file.
- 3) Generate a digital certificate using the Keytool tool
Keytool-genkey-v-keystore liufeng.keystore-alias liufeng.keystore-keyalg rsa-validity 20000
- Description
1) Keytool is the tool name,-genkey means to generate a digital certificate operation, and-V to print out the details of the generated certificate, displayed in the DOS window;
2)-keystore Liufeng.keystore indicates the file name of the generated digital certificate is "Liufeng.keystore";
3)-alias Liufeng.keystore that the certificate alias is "Liufeng.keystore", of course, it can not be the same as the above file name;
4)-keyalg RSA indicates that the algorithm used to generate the key file is RSA;
5)-validity 20000 indicates that the digital certificate is valid for 20,000 days, meaning that the certificate will expire after 20,000 days
When you execute the above command to generate a digital certificate file, you are prompted to enter some information, including the certificate's password.
- 4) sign the Android app with the Jarsigner tool
Jarsigner-verbose-keystore Liufeng.keystore-signedjar notepad_signed.apk notepad.apk liufeng.keystore
- Description
1) Jarsigner is the tool name,-verbose indicates the details of the signature process is printed out, displayed in the DOS window;
2)-keystore Liufeng.keystore indicates the location of the digital certificate used by the signature, there is no write path, which is indicated in the current directory;
3)-signedjar notepad_signed.apk notepad.apk to notepad.apk file signature, signed file name is notepad_signed.apk;
4) The last Liufeng.keystore represents the alias of the certificate, which corresponds to the name after the-alias parameter when generating the digital certificate
- 5) Use the Zipalign tool to optimize the signed apk(not required but recommended)
- Zipalign-v 4 notepad_signed.apk notepad_signed_aligned.apk
View SHA1 in Android Studio is in
The first step, open Android Studio Tools->open Terminal ...
Second step, input command: keytool-v-list-keystore Keystore.jks
You can switch to your own ja.
For example: Keytool-genkey-v-keystore jackluo.keystore-alias jackluo.keystore-keyalg rsa-validity 20000
C:\users\jackluo\.android>keytool-list-keystore Jackluo.keystore
Your KeyStore contains 1 entries
Jackluo.keystore, 2015-11-25, Privatekeyentry,
Certificate Thumbprint (SHA1): ad:fa:d8:aa:d4:a4:0f:33:8a:79:6b:fe:80:5c:b6:51:e7:7b:38:3b
C:\users\jackluo\.android>
C:\users\jackluo\.android>keytool-list-keystore Jackluo.keystore
Enter KeyStore Password:
KeyStore Type: JKS
KeyStore provider: SUN
Your KeyStore contains 1 entries
Jackluo.keystore, 2015-11-25, Privatekeyentry,
Certificate Thumbprint (SHA1): ad:fa:d8:aa:d4:a4:0f:33:8a:79:6b:fe:80:5c:b6:51:e7:7b:38:3b
Android Studio signatures Use the Go