Ant official site such as: http://ant.apache.org/manual/index.html here you can get more information about ant.
1. download and install the ant tool and configure environment variables.
(1). Run the following command on the terminal: fql @ fql-system-product-Name :~ /Desktop $ gedit ~ /. Bashrc
(2) modify the bashrc file and add it to path and classpath.
export ANT_HOME=~/fql_zlyy/tools/apache-ant-1.8.3export PATH=$ANDROID_SDK/platform-tools:$ANDROID_SDK/tools:$JAVA_HOME/bin:$ANT_HOME/bin:$PATHexport CLASSPATH=$ANDROID_SDK/platform-tools/lib:$ANDROID_SDK/tools/lib:$JAVA_HOME/lib:$ANT_HOME/lib:$CLASSPATH
(3). Check whether the installation is successful on the terminal. I installed version 1.8.3.
Fql @ fql-system-product-Name :~ /Desktop $ ant-versionapache ant (TM) version 1.8.3 compiled on February 26 2012
2. Compile the android Project
(1) Open the terminal, enter the project directory, and enter the following command $ Android update project-PAnttest-T Android-17
-P specifies the project path,-T specifies the android sdk api level used by the Project
AnttestEnter the specific path of the project. If the path is under the parent path of the current project, enter anttest
(2) edit the build. xml generated under the project directory and change the name attribute of the project element to the project name. This name affects the generated APK file name. For example, testantbuild.
(3) compile various types of versions
Compile the debug version, enter the command $ ant debug (after the compilation is successful, the TestAntBuild-debug.apk will be generated under the bin/directory)
Compile the keystore and alias required by the release version, and edit the ant. properties file under the project directory (if not, create your own ),
Example: Key. Store =/home/fql_zlyy/opt/fql. Key
Key. Alias = fql_release
Key. Store. Password = fql
Key. Alias. Password = fql
Because the path configured in ant. properties is related to the development environment, do not add ant. properties to the version management system.
Compile the release version, enter the command $ ant release compiled successfully, the bin/directory will generate the TestAntBuild-release.apk
3. Custom Android project editing
When developing Android applications, developers usually write a large number of logs for debugging (log. V log. I log. D log. E log. w), but we only want
The log information of log. e is displayed, but other log information is not displayed, which helps improve program performance.
(1). Create a project anttest and create the corresponding class code as follows: // The slog class can be skipped, but it is only packaged for logs.
package com.example.anttest;import android.app.Activity;import android.os.Bundle;import android.util.Log;import android.view.Menu;public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Slog.setTag("MainActivity"); for (int i = 0; i < 10; i++) { Slog.i("the hope is everyever"); } Slog.e("Error Test Successfully"); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_main, menu); return true; }}
package com.example.anttest;public class Config{ public final static boolean SHOW_ALL_LOG = false;}
(2) create a config folder under the anttest directory, and create a config. Java class under this folder. The Code is as follows:
package com.example.anttest;public class Config{ public final static boolean SHOW_ALL_LOG = @CONFIG.FOO@;}
NoteToken hereAnd pay attention to other placesIt is exactly the same as the config class created in (1 )..
(3). Modify the build. xml file
Tip: InStep 2. Compile the android ProjectThe first step is to generate the build. xml file.
<property file="ant.properties" /> <target name="-pre-compile"> <copy file="config/Config.java" todir="${source.dir}/com/example/anttest" overwrite="true" encoding="utf-8"> <filterset> <filter token="CONFIG.FOO" value="${config.foo}"/> </filterset> </copy> </target>
In<Property file = "ant. properties "/> ). create a config folder under the anttest directory. java files created in Java) to anttest/src/COM. example. to overwrite
Com. example. anttestThe config. Java file created under the package. Replace @ config. Foo @; with the value indicated by config. Foo under ant. properties. In this way, the program runs dynamically.Ant. Properties.
The content of ant. properties is as follows:
key.store=/home/fql/fql_zlyy/fql_key.keykey.alias=fql_releasekey.store.password=fqlkey.alias.password=fqlconfig.foo=false
(4) After the configuration is complete, directly enter the command:
Fql @ fql-system-product-Name :~ /Desktop $ ant release
You can.
If you have any questions, please leave a message !!!!
4. References
Using Ant to automate building Android applications
Building and running from the command line