Android Tutorials - Herong's Tutorial Examples - v3.05, by Herong Yang
First Apache Ant Build File Example
This section provides a tutorial example on how to write an Apache Ant build file to compile and run a simple Java application, Hello.java.
Now let's try to create Apache Ant build file to build and run the Hello Java application.
1. Create the application home folder and sub solders:
C:\>mkdir \herong\Hello C:\>mkdir \herong\Hello\src C:\>mkdir \herong\Hello\build
2. Copy the application source file, Hello.java, into the source folder:
C:\>copy Hello.java \herong\Hello\src
3. Create the build file, .\build.xml, using a text editor:
<project> <!-- build.xml - Copyright (c) 2015, HerongYang.com, All Rights Reserved. --> <target name="compile"> <delete dir="build"/> <mkdir dir="build/classes"/> <javac srcdir="src" destdir="build/classes"/> <mkdir dir="build/jar"/> <jar destfile="build/jar/Hello.jar" basedir="build/classes"> <manifest> <attribute name="Main-Class" value="Hello"/> </manifest> </jar> </target> <target name="run"> <java jar="build/jar/Hello.jar" fork="true"/> </target> </project>
4. Test the build process with the "ant" command:
C:\>cd \herong\Hello C:\herong\Hello>\local\apache-ant-1.9.5\bin\ant compile Buildfile: C:\herong\Hello\build.xml compile: [delete] Deleting directory C:\herong\Hello\build [mkdir] Created dir: C:\herong\Hello\build\classes [javac] C:\herong\Hello\build.xml:9: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false forepeatable builds [javac] Compiling 1 source file to C:\herong\Hello\build\classes [mkdir] Created dir: C:\herong\Hello\build\jar [jar] Building jar: C:\herong\Hello\build\jar\Hello.jar BUILD SUCCESSFUL Total time: 0 seconds C:\herong\Hello>\local\apache-ant-1.9.5\bin\ant run Buildfile: C:\herong\Hello\build.xml run: [java] Hello world! BUILD SUCCESSFUL Total time: 0 seconds
Congratulations, you have successfully created a working Apache Ant build file!
Note that if you are using Ant 1.8 with JDK 1.8, you will get the following error:
BUILD FAILED C:\herong\Hello\build.xml:9: Class not found: javac1.8
You need replace Ant 1.8 with Ant 1.9.
Table of Contents
Installing JDK 1.8 on Windows System
Installation of Android SDK R24 and Emulator
►Installing Apache Ant 1.9 on Windows System
Downloading and Installing Apache Ant 1.9
Preparations on Using Apache Ant Tool
►First Apache Ant Build File Example
Developing First Android Application - HelloAndroid
Android Application Package (APK) Files
Android Debug Bridge (adb) Tool
AboutAndroid - Application to Retrieve System Information
android.app.Activity Class and Activity Lifecycle
View Objects and Layout Resource Files
Using "adb logcat" Command for Debugging
Build Process and Package File Content
Samsung Galaxy Tab 3 Mini Tablet
USB Debugging Applications on Samsung Tablet
USB Debugging Applications on LG-V905R Tablet