Google provides Android SDK support Ant Auto build [1], you can use debugging and release two modes to build, the difference between the two modes is that the debug mode Ant calls the built-in debug key, and release mode calls the private key you provide.
First install Ant and add it to your execution path in path [2].
Debug Mode Build
In debug mode, Ant automatically signs your Android app with a debug key and optimizes it with zipalign.
To build in debug mode, first enter the Android project root directory at the command line and build it using ANT Boot debug mode:
$ ant Debug
The command creates a file named <your_project_name>-debug.apk in the project's bin/directory, which has been signed with a debug key and is Zipalign optimized.
Each time the resource in the project changes, you must rerun the command to compile and package.
Release Mode Build
When you're ready to launch your Android app, you'll have to build it using release mode, before you have to have a private key and use that key to sign the release package.
You now have two build scenarios, one is to build an unsigned release package and then manually sign and optimize it, and the other is to use scripts to automatically sign and optimize.
Building an unsigned release package
You can choose not to sign the build, but then you have to manually sign and optimize.
To make an unsigned build, go to the project root at the command line and use ANT to compile your project in release mode:
$ ant Release
This command creates a file named <your_project_name>-unsigned.apk in the project's bin/directory. However, the file cannot be installed on the Android device until you sign it with your private key. The next thing you need to do is sign the. apk file and use the Zipalign tool to optimize it, see Signing Your applications.
Building signed and optimized packages
If you want, you can configure the Android build script to automatically sign and optimize your app package. The practice is to edit the Ant.properties file, where you configure the private key KeyStore path to use and the key alias. [3] Ant will pop up during the build process to ask for a password for the key and key alias, and then you will get a final release package that can be marketed.
To find and edit the Ant.properties file in the project root directory, create one without the file. Add two fields Key.store and Key.alias to the file. For example:
key.store=path/to/My.keystorekey.alias=mykeystore
Save the exit and run the ANT command to start the build:
$ ant Release
You will be asked to enter the KeyStore and alias password in the middle, and eventually you will get a file named <your_project_name>-release.apk in the bin/directory, which is signed with the private key specified in Ant.properties. And after Zipalign optimization, you can install and distribute the file at any time. You can upload the file to a Web server and then use your browser to open the download link on your Android device to complete the automatic installation.
Note:
[1] Android SDK provides Android tools to automatically generate a Build.xml file, Ant will use this file for automatic construction. The Ant tool is not included with the Android SDK and you can download and install ant from the Apache Ant home page.
[2] Before calling Ant, you also make sure that your JDK path is declared in the environment variable java_home. The default installation path for the JDK in Windows is the program Files folder, which causes ant to fail because it contains a space character. To fix this problem, you can set the JAVA_HOME environment variable to the following:
Set java_home=c:\progra~1\java\<jdkdir>
But the best way is to install the JDK into a directory with no whitespace.
[3] Since the password you entered during the Ant build process is displayed on the screen, if you are concerned, you can choose to use the Jarsigner tool for manual signature and optimization.
Report:
1. Signing Your Applications-android app signature.
[Android] build Android app based on Linux command line (iv): command line Build