The laziest way to generate apk is:
As long as you have run an android project, you can find the apk file with the same name as the project in the bin folder of the working directory. By default, this apk has been signed by the debugging user.
If you want to sign the apk yourself:
Importance of signature
In order to ensure the legal ID of each application developer and prevent some openers from confusing and replacing the installed programs with the same package name, we need to uniquely sign the APK files we publish to ensure the consistency of the versions we publish each time (for example, automatic updates will not be impossible to install because of inconsistent versions).
Step 2: Sign.
A. create a key
B. use the key generated in step a to sign the apk.
3. Specific operations
Method 1: sign apk (principle) on the command line.
You need Keytool.exe (located in jdk 1.6.0_24\jre\bin directory) to create the key, and use jarsigner.exe (located in jdk 1.6.0_24\bin directory) to sign the apk. After adding the directories where the last two softwares are located to the environment variable path, open the cmd input.
d:\ & gt; Keytool -genkey-alias demonstration. Keystore-KeyalG RSA-Validity 40000-Keystore demo.keystore/* Description: -genkey Generate Keys? -alias demo . keystore alias demo . keystore? -keyalg RSA encrypts the signature with RSA algorithm? -40,000 days? -keystore demo . keystore */D:\ & gt; Detailed keystore demonstration. Jardemo _ signed.apkdemo.apk demo.keystore/* description of keystore signature:-output signature details in detail? -Keystore? Demo.keystore keystore location? -signed jardemo _ signed.apkdemo. apkdemo.keystore is formally signed, and the three parameters are the signed file demo _ signed, the file to be signed demo.apk and keystore demo.keystore.*/
Note: demo.apk in the bin directory of android project has been signed by debug user by default, so you can't use the above steps to sign the file again. The correct step should be: right-click the item-> The apk exported by anroid tools-export unsigned application package is signed by the above steps.
Method 2: Export apk with signature using Eclipse.
Eclipse can directly export the final apk with signature, which is very convenient and recommended. The steps are as follows:
Step 1: Export.
Step 2: Create a keystore keystore, enter the location and password of the keystore export, and remember the password, which will be used next time.
Step 3: Fill in the keystore information, and fill in the password, service life and organizational unit information of some apk files.
Step 4: Generate a signed apk file, and that's it.
Step 5: If the version is released next time, re-sign it with the previously generated keystore.
Step 6: Next step, next step, end!
Method 3: export signed apk with IntelliJ IDEA?
The method steps are basically the same as Eclipse, and the approximate operation path is: menu tools->; andr oid-& gt; Export signature apk.
4. After signing, use zipalign to optimize your APK file.
Unsigned apk cannot be used or optimized. Google recommends zipalign.exe (located in android-sdk-windows\tools directory) to optimize the signed apk:
d:\ & gt; zip align-v 4 demo _ signed . apk final . apk
As mentioned above, zipalign can align the uncompressed data in the apk file on the boundary of 4 bytes (4 bytes is a good value), so that the android system can use the mmap () function to read the file, which can achieve high performance in reading resources.
PS: 1。 Alignment on a 4-byte boundary means, generally speaking, that the compiler reads the results in units of 4 bytes, so that the CPU can access variables efficiently and quickly (misaligned).
2. The root of alignment: Davlik virtual machine in android system uses its own proprietary format DEX. DEX has a compact structure. In order to make the runtime performance better, it can be further optimized by "alignment", but the size will generally increase.
5. The influence of signature on your App.
You can't just make an APP. You may have a grand strategic project. If you want to get involved in life, services, games and systems, you can't just make an APP. Google recommends that you use the same signing certificate for all applications.
With your own same signing certificate, no one can overwrite your application, even if the package name is the same, so the effect is as follows:
1) App upgrade. The upgraded software with the same signature can normally overwrite the old version of the software, otherwise the system will find that the signature certificate of the new version is inconsistent with that of the old version, and the new version is not allowed to be installed successfully.
2) App modularity. The Android system allows the same App to run in the same process. If they run in the same process, it is equivalent to the same App, but you can update it separately. This is an App-level modular idea.
3) Allow code and data sharing. Signature-based permission tags are provided in android. Through the allowed settings, we can access and enjoy different applications, as shown below:
Android manifest . XML:& lt; Permission Android: protectionlevel = "normal"/>
Among them, the protectionLevel label has four values: normal (default), dangerous, signature and signature system. Simply put, normal is low risk, and all apps can't access and enjoy this app. Danger is high risk, and all apps can access and enjoy this app. Signature means that applications with the same signature can access and * * * enjoy this application. SignatureOrSystem means that the App in the system image and the App with the same signature can access and * * * enjoy this App. Google does not recommend using this option, because the signature is enough. In general, you will use this license when you need * * * to enjoy certain functions in an image.