To publish an Android program using the command line

Source: Internet
Author: User

In the process of developing the Android program, we use ant debug and ant installd These two commands are enough, do not involve the APK signature.

But in the official release of our Android program, you need to sign the APK. ant releasegenerate a release version of the program.

ant releaseThe package will generate an unsigned apk: xxx-release-unsigned.apk . Then try to ant.properties sign this apk with the KeyStore file that is given inside, generate xxx-release.apk . If ant.properties no keystore is given, the signed apk is not generated. When you run ant installr , you will fail because ant cannot find it xxx-release.apk .

There are two workarounds: (1) Set Key.store and Key.alias in the Ant.properties file, and then rerun ant release and ant installr command. (2) Use command to xxx-release-unsigned.apk sign and zipalign, generate xxx-release.apk , and then run ant installr .

Either way, we have to prepare the KeyStore file first. The JDK provides a keytool program that can generate Key.store files.

keytool.exe -genkey -alias jollywing.android.keystore -keyalg RSA -validity 36500 -keystore android.keystore
    • -genkey indicates that the action to be performed is to generate KeyStore.
    • -alias is the alias of this keystore.
    • The-KEYALG represents the algorithm that generates the key pair.
    • The-validity represents a validity period, where 36500 is close to 100 years.
    • -keystore Specifies the final generated keystore file name.

Run the command and you are prompted for the KeyStore password. This password will be asked when you sign the APK.
You will then be asked for information about your name, your organization, your region, and so on.
The Key.alias key password is also queried, and the direct carriage return indicates the use of the same password as the KeyStore.

The command runs successfully and you get a warning message:

The JKS KeyStore uses a dedicated format. Recommended use of "Keytool-importkeystore-srckeystore Android.keystore-destkeystore android.keystore-deststoretype pkcs12" Migrate to industry standard format PKCS12.

We can run the command in the warning message to convert the KeyStore into a standard format. This step is optional.

Then we can sign it. Either way, one is signed with the Ant Release command, and the other is a manual signature.

If you sign with the Ant Release command, we put Android.keystore under the project root directory, which is the same directory as Build.xml and ant.properties. Then edit the ant.properties to add the following content.

key.store=android.keystorekey.alias=jollywing.android.keystorekey.store.password=<刚才设置的密钥库口令>key.alias.password=<刚才设置的密钥库别名口令>

If Android.keysotre is not placed in the project root directory, it is best to use absolute paths to indicate where the KeyStore file is placed.

ant releaseand then ant installr it's OK.

Finally, I'll tell you how to xxx-release-unsigned.apk sign with a command.

Use the Jarsigner command in the JDK (the APK is a jar package file).

jarsigner -keystore <keystore文件的路径> <xxx-release-unsigned.apk的路径> 密钥库别名

After the command is run, XXX-RELEASE-UNSIGNED.APK is already signed.

zipalign -v 4 <xxx-release-unsigned.apk的路径> <要生成的xxx-release.apk的路径>

zipalignThe command is placed in the Build-tools directory of the Android SDK.

Well, a ready-to-publish apk is freshly baked, adb install <xxx-release.apk的路径> try it out. If the xxx-release.apk is placed in the bin directory of the project, it can also be run directly ant installr .

2017-11-25 Saturday

To publish an Android program using the command line

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.