Android tip 03: re-sign the APK

Source: Internet
Author: User

1. Generate the android APK package signature certificate
1) switch to the JDK bin directory in Doc
Cd c: \ Program Files \ Java \ jdk1.6.0 _ 18 \ bin
2) run the following command
Keytool-genkey-alias android123.keystore-keyalg RSA-validity 20000-keystore android123.keystore
/* Explanation: keytool is a built-in certificate tool of Java JDK.
-Genkey parameter: generate a certificate (security certificate for copyright and Identity Recognition)
-The alias parameter indicates that the certificate has an alias.-alias mine. keystore indicates that the certificate alias is mine.
-Keyalg RSA indicates the encryption type, and RSA indicates that encryption is required to prevent theft by others.
-Validity 20000 indicates the validity period of 20000 days (K3
-Keystore mine123.keystore indicates that the certificate name to be generated is mine123.
*/
 
After entering the carriage return, the screen is displayed:
Enter the keystore password: [do not display the password] (generally 20 digits are recommended. It is best to remember the password and use it later)
Enter the new password again: [do not display the password]
What is your first name and last name?
[UNKNOWN]: Lili
What is the name of your organization?
[UNKNOWN]: Snoopy
What is your organization name?
[UNKNOWN]: Snoopy team
What is the name of your city or region?
[UNKNOWN]: Beijing
What is the name of your state or province?
[UNKNOWN]: Beijing
What is the two-letter country code for this unit?
[UNKNOWN]: CN
CN = Lili, u = Snoopy, O = Snoopy team, L = Beijing, St = Beijing, c = cn correct?
[No]: Y
Enter the master password of <mine. keystore>
(If the password is the same as the keystore password, press Enter ):

View c: \ Program Files \ Java \ jdk1.6.0 _ 18 \ bin, generate the certificate key for signature later: mine123.keystore

Here, if you try to generate a signature file in eclipse, the file size is also 2 kb, And the alias will be entered during the generation process.

2. Delete the previous signature file
1) decompress the APK file with the decompression tool (for example, decompress it to D: \ sign \ phonebook)

Analysis of compressed Package content:

  • Androidmanifest. xml

This file must be defined and contained by each application. It describes the application name, version, permission, referenced library file, and other information. [,], to upload the APK to Google market, you also need to configure the XML. Androidmanifest. XML in the APK is compressed. You can use the axmlprinter2 tool [,] to unbind it. The specific command is: Java-jar axmlprinter2.jar androidmanifest. xml

  • META-INF directory

The META-INF directory stores signature information to ensure the integrity of the APK package and system security. When eclipse compiles an APK package, it will do a verification calculation for all the files to be packaged, and put the calculation result under the META-INF directory. This ensures that the files in the APK package cannot be replaced at will. For example, after obtaining an APK package, if you want to replace an image, a piece of code, or a piece of copyright information, it is basically impossible to directly decompress, replace, and re-package the package. This increases the difficulty of virus infection and malicious modification, and helps protect the security of the system.

  • Res directory

The res directory stores resource files. Including images and strings.

  • Lib directory

The sub-directory armeabi In the lib directory stores some so files. In this place, I will talk a few more words, all of which are found during the development process. During packaging, eclipse will follow the naming rules for file names (LIB ****. so) to package the so file, the start and end must be "lib" and ". so ", otherwise it will not be packaged into the APK file. Other non-Eclipse development environments have not been tested. If you are using sdks and ndk for development, this part is very important. You can even package some files that are not so files into the APK by renaming them, what you can do depends on what you want to do!

  • Assets Directory

The Assets Directory can store some configuration files. The content of these files can be obtained through related APIs during the program running. The specific method can refer to the SDK example: In the SDK \ 1.6 \ android-sdk-windows-1.6_r1 \ platforms \ Android-1.6 \ samples \ apidemos example, there is a COM. example .. android. APIS. in this example, a text file is stored in the asset directory of the project, and the TXT file is processed as a common file. The processing process is in readasset. java. Similarly, asset can also store other files.

  • Classes. Dex File

Classes. Dex is a Java bytecode file generated after Java source code compilation. However, because the Dalvik Virtual Machine Used by Android is incompatible with the standard Java virtual machine, the DEX file is different from the class file, regardless of the file structure or opcode. Currently, common Java decompilers cannot process Dex files. The android simulator provides dexdump, A decompilation tool for Dex files. The usage is to first start the android simulator, use the ADB push upload simulator to view the DEX file, and then log on to the simulator through the ADB shell, find the DEX file to be viewed, and execute dexdump
Xxx. Dex. In addition, dedexer is the only open-source tool that can be found on the Internet to decompile Dex files. You need to compile the source code by yourself.

  • Resources. ARSC

Compiled binary resource file"
 
2) Find the directory META-INF below and delete the directory META-INF
3). Use the zip tool to package the entire phonebook folder into a zip package and change the suffix to APK (Note: There is no second-level root directory in your phonebook.zip file)
 
3. re-sign the APK File
1). Copy the certificate to the same directory as the APK file to be re-signed (for example, copy to D: \ sign)
2) switch to the directory where you need to re-upload the APK file in the doc.
Cd d: \ sign
3). Run the following command
Jarsigner-verbose-keystore mine123.keystore-signedjar phonebook_signed.apk phonebook.apk mine. keystore
/* Explanation: hjarsigner is a Java signature tool.
-Verbose parameter indicates that the signature details are displayed.
-Keystore: Use mine123.keystore in the current directory to sign the certificate file.
-Signedjar phonebook_signed.apk?generated after the signature, phonebook.apk indicates the unsigned APK Android software, and mine. keystore indicates the alias
*/
After entering the carriage return, the screen is displayed as follows:

View the D: \ signdirectory. The phonebook_signed.apk file has been generated for the new signature.

In addition, sometimes you will find that the APK package in this way cannot be used in some places. The article "simple modification of APK and re-signature" provides a more convenient solution.

References:

Re-sign the APK File

Related Article

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.