Android Learning Series (1) -- sign an App (signature an apk)

Source: Internet
Author: User

This article is a must-have knowledge for Android Developers. It is specially compiled and summarized for everyone. It is not perfect but useful. 1. Significance of Signature
To ensure the legal ID of each application developer and prevent some open vendors from confusing and replacing installed programs by using the same Package Name, we need to make a unique signature for the APK file we released, ensure the consistency of the versions we release each time (for example, automatic update will not be unable to be installed because of version inconsistency ). 2. Signature steps
A. Create a key
B. Use the key generated in step a to sign the apk 3. Method 1: sign the apk on the command line (principle)
Keytool.exe (located in jdk1.6.0 _ 24 \ jre \ release (located in the directory of jdk1.6.0 _ 24 \ bin). Add the directories of the above two software to the environment variable path and open cmd and enterCopy codeNote: by default, demo.apk under the binlog of the androidproject uses the debug user signature. Therefore, you cannot use the preceding steps to re-sign the file. The correct steps should be: Right-click the project and choose Anroid Tools-Export Unsigned Application Package to use the above signature for the exported apk. Method 2: Use Eclipse to export the signed apk
Eclipse can directly export the final apk with a signature, which is very convenient and recommended. The steps are as follows:
Step 1: export.
<Ignore_js_op>
Step 2: Create the keystore, enter the location and password for the keystore export, and remember the password. It will be used in the next Use existing keystore.
<Ignore_js_op>
Step 3: Enter the keystore information, password of some apk files, expiration time, and organization unit information.
<Ignore_js_op>
Step 4: generate an apk file with a signature, and this will end.
<Ignore_js_op>
Step 5: Use the previously generated keystore to sign the next release.
<Ignore_js_op>
Step 6: Next, Next, end! Method 3: Use IntelliJ IDEA to export the signed apk
The steps are basically the same as those in Eclipse. The approximate operation path is menu Tools> Andrdoid> Export signed apk. 4. After signing, use zipalign to optimize your APK file.
Unsigned apk cannot be used or optimized. After signing, apkgu song recommends using zipalign.exe (in the android-sdk-windows \ tools directory) to optimize it:Copy codeAs shown above, zipalign can align uncompressed data in the apk file on the 4-byte boundary (4 bytes are a good value), so that the android system can use mmap () (please check the purpose of this function) function reading files can achieve high performance in reading resources,
PS: 1. alignment on the boundary of four bytes means that, in general, it refers to the result that the compiler reads four bytes as a unit. In this case, the CPU can perform efficient and fast access to variables (not aligned before ).
2. root of alignment: The Davlik virtual machine in the android system uses its proprietary DEX format. The DEX structure is compact. In order to improve the running performance, you can further use alignment to further optimize it, but the size usually increases. 5. Influence of signature on your App.
You can't just make one APP. You may have a grand strategic project. If you want to plug in every field of life, service, game, and system, you can't just make one APP, google recommends that you use the same signature certificate for all your apps.
With your own signature certificate, no one will be able to overwrite your application. Even if the package name is the same, the impact may be:
1) Upgrade the App. Upgrade software with the same signature can normally cover older versions of the software. Otherwise, the system will find that the new version of the signature certificate is inconsistent with the old version of the signature certificate, and the new version is not allowed to be installed successfully.
2) App modularization. The android system allows identical apps to run in the same process. If they run in the same process, they are equivalent to the same App, but you can upgrade them separately, this is an App-level modular approach.
3) Allow Code and data sharing. Android provides a signature-based Permission tag. With the allowed settings, we can access and share different apps as follows:Copy code

The protectionLevel tag has four values: normal (default), dangerous, signature, and signatureOrSystem. In short, normal is a low risk. All Apps cannot access or share this App. Dangerous is highly risky, and all apps can access and share this App. Signature means that apps with the same signature can access and share this App. SignatureOrSystem indicates that the App in the image System and the App with the same signature can access and share this App. Google recommends not to use this option because the signature is sufficient, generally, this license is used when a specific function needs to be shared in an image.
Remember to keep the two passwords of your signature certificate safe. Do not tell anyone or copy your keystore to others, including me!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.