Home > Article > Computer Tutorials > How to use Eclipse tools to package and sign AndroidApk files
Start eclipse and create the Android project
In the process of packaging and signing an Android project, you need to select the target project first, right-click on the project, and then select [Android tools]-》[Export Signed Application Package..].
Enter the signature packaging management window, confirm the project name in the first step, and click to proceed to the next step
Select the keystore (that is, the signature file), you can choose to use the already defined keystore, or create a new signature file;
In another experience, the author will introduce in detail how to create a new keystore, but here, we will temporarily use the predefined signature file.
When selecting the keystore, first enter the storage directory, find and select the keystore file, then enter the password, and finally click Next to proceed.
When installing eclipse adt, a debug.keystore file will come with it by default, and its password is: android.
If you are using a custom signature file, you need to enter the corresponding defined password
Choose a key to encrypt, the password is the same as above;
Of course readers can also customize a new key
After selecting the APK storage directory, click [Finish], and eclipse will automatically package it. After the packaging is completed, you can find the signed APK file in the previously set storage directory.
If you just want to know how to sign and download the signing tool, please look directly at the "How to use SignApk.jar to sign an apk or zip file" section. If you wish to create your own certificate, please read from the beginning.
Preparation knowledge:
When you want to release a software or home-made ROM, you need to use a certificate that has used a private key to sign the .apk or .zip file. The Android system uses certificates to identify the authentication relationship established between the software author and the software. The most common way to create a certificate is to use the keytool tool and then use the jarsigner tool to sign it. However, this tutorial will provide an easier method for most people, and that is to use a tool called SignApk.jar.
SignApk.jar is a tool that is already included in the Android platform source code package. You can download it in the attachment of this post. If you want to use SignApk.jar, you first need to create a private key with the corresponding certificate/public key. You can use Openssl to create a private/public key pair. In Unix/Linux systems, using Openssl is relatively easy. For Windows users, you can download the Windows version of Openssl tool in the attachment of this post or through this link.
In the Windows version, you can use OpenSSL to create a private/public key pair (that is, a certificate file). Here are the brief steps of the creation process: Step 1: Download and install OpenSSL First, you need to download and install the appropriate version of OpenSSL from the official OpenSSL website (https://www.openssl.org/). Step 2: Open Command Prompt In Windows, press the Win R key, enter "cmd" and press the Enter key to open the command prompt window. Step 3: Navigation
Download openssl-0.9.8k_WIN32.zip in the attachment
Extract the downloaded compressed package to an appropriate location on your computer, such as C:\OpenSSL.
In the OpenSSL\bin folder, enter the commands in the following order (please use the CMD command line tool). In the second step, you need to enter some information. See the attached picture for specific operations.
1. openssl genrsa -out key.pem 1024
2. Open a command prompt window and enter the following command: openssl req -new -key key.pem -config C:\OpenSSL\openssl.cnf -out request.pem.
3. Execute the following command to generate a certificate: openssl x509 -req -days 9999 -in request.pem -signkey key.pem -out certificate.pem
Execute the following command to convert the private key in PEM format to the private key in DER format: `openssl pkcs8 -topk8 -outform DER -in key.pem -inform PEM -out key.pk8 -nocrypt` This command uses the OpenSSL tool to convert the PEM format private key in the input file `key.pem` to DER format, and saves the converted private key as a `key.pk8` file. Use the `-topk8` parameter to specify the generation of a private key in PKCS#8 format, the `-outform DER` parameter to specify that the output is in DER format, the `-in` and `-inform PEM` parameters to specify that the input file is in PEM format, `-out` The parameter specifies the output file name `key.pk8`, and the `-nocrypt` parameter indicates
Big Star Tip: If your recovery does not support the signature verification switching function, you may encounter a signature verification failure prompt when using the certificate file you generated to sign the ROM. This is because the private key carried in almost all third-party recoveries currently is testkey. Please note that the android.zip file in the attachment has been updated to the testkey certificate file.
How to use SignApk.jar to sign an apk or zip file:
Download the android.zip in the attachment
Extract the downloaded compressed package to any location on your computer (for example: C:\android)
If the JAVA environment has not been installed on your computer, please download and install it.
If you have generated your own private key/public key pair, copy the certificate.pem and key.pk8 files to the android folder you extracted.
Use the CMD command line tool to cd to the android folder, and then enter: (For the package I provided, you only need to place the file to be signed in the android folder, and then drag it to the corresponding batch file)
java -jar signapk.jar certificate.pem key.pk8 your-app.apk your-signed-app.apk
or
Use the Java command line tool to sign an update package (your-update.zip) by executing the following command: java -jar signapk.jar certificate.pem key.pk8 your-update.zip your-signed-update.zip
The above is the detailed content of How to use Eclipse tools to package and sign AndroidApk files. For more information, please follow other related articles on the PHP Chinese website!