Building Android project using Ant tool

Last Updated:

  1. shahid106

    shahid106 New Member This Topic's Starter

    Feb 18, 2010
    Likes Received:
    Hello everybody,
    I am new in Android application.
    I am facing a problem when i am going to build Android project using Ant tool.

    I have made a build.xml file and it is giving that BUILD SUCCESSFUL.
    But the AndroidManifest.xml file is not adding with the .apk file.
    For that when i am going to install the .apk file it is giving the message "AndroidManifest.xml file not found".

    I am giving the Build.xml file below.

    <?xml version="1.0" ?>
    <project name="HelloWorldCommandLine" default="package" basedir=".">
    <property name="sdk-folder" value="C:/android-sdk-windows-2" />
    <property name="android-tools" value="${sdk-folder}/tools" />
    <property name="android-framework" value="${android-tools}/lib/framework.aidl"/>
    <!-- The intermediates directory -->
    <!-- Eclipse uses "bin" for its own output, so we do the same. -->
    <!-- Use full path for output dir - FIX - BLOCK START -->
    <property name="outdir" value="${basedir}/bin" />
    <!--<property name="outdir" value="bin" /> -->

    <!-- No user servicable parts below. -->
    <!-- Input directories -->
    <property name="resource-dir" value="res" />
    <property name="asset-dir" value="assets" />
    <property name="srcdir" value="src" />
    <!-- Output directories -->
    <property name="outdir-classes" value="${outdir}/classes" />
    <!-- Create in the source directory -->
    <property name="outdir-r" value="src" />
    <!-- Intermediate files -->
    <property name="dex-file" value="classes.dex" />
    <property name="intermediate-dex" value="${outdir}/${dex-file}" />
    <!-- The final package file to generate -->
    <property name="out-package" value="${outdir}/${}.apk"/>
    <!-- Tools -->
    <property name="aapt" value="C:/android-sdk-windows-2/platforms/android-2.0/tools/aapt.exe" />
    <property name="aidl" value="C:/android-sdk-windows-2/platforms/android-2.0/tools/aidl.exe" />

    <condition property="dxbat" value="C:/android-sdk-windows-2/platforms/android-2.0/tools/dx.bat"
    else="C:/android-sdk-windows-2/platforms/android-2.0/tools/dx" >
    <os family="windows"/>

    <!--<property name="dx" value="${android-tools}/dx" />-->

    <property name="adb" value="${android-tools}/adb" />
    <property name="android-jar" value="C:/android-sdk-windows-2/platforms/android-2.0/android.jar" />
    <property name="zip" value="zip" />
    <!-- Rules -->
    <!-- Create the output directories if they don't exist yet. -->
    <target name="dirs">
    <mkdir dir="${outdir}" />
    <mkdir dir="${outdir-classes}" />
    <!-- Compile this project's .java files into .class files. -->
    <target name="compile" depends="dirs, resource-src, aidl">
    <javac encoding="ascii" target="1.5" debug="true" extdirs=""
    bootclasspath="${android-jar}" />

    <!-- Generate the file for this project's resources. -->
    <target name="resource-src" depends="dirs">
    <exec executable="${aapt}" failonerror="true">
    <arg value="package" />
    <arg value="-m" />
    <arg value="-J" />
    <arg value="${outdir-r}" />
    <arg value="-M" />
    <arg value="AndroidManifest.xml" />
    <arg value="-S" />
    <arg value="${resource-dir}" />
    <arg value="-I" />
    <arg value="${android-jar}" />
    <!-- Generate java classes from .aidl files. -->
    <target name="aidl" depends="dirs">
    <apply executable="${aidl}" failonerror="true">
    <arg value="-p${android-framework}" />
    <arg value="-I${srcdir}" />
    <fileset dir="${srcdir}">
    <include name="**/*.aidl"/>

    <!-- Convert this project's .class files into .dex files. -->
    <target name="dex" depends="compile">
    <exec executable="${dxbat}">
    <!--failonerror="true"> -->
    <!--<arg value="-JXmx384M" />-->
    <arg value="--dex" />
    <arg value="--output=${basedir}/${intermediate-dex}" />
    <arg value="--locals=full" />
    <arg value="--positions=lines" />
    <arg path="${basedir}/${outdir-classes}" />
    <!-- Put the project's resources into the output package file. -->
    <target name="package-res-and-assets">
    <echo>Packaging resources and assets...</echo>
    <exec executable="${aapt}">
    <!-- failonerror="true"> -->
    <arg value="package" />
    <arg value="-f" />
    <arg value="-c" />
    <arg value="-M" />
    <arg value="AndroidManifest.xml" />
    <arg value="-S" />
    <arg value="${resource-dir}" />
    <arg value="-A" />
    <arg value="${asset-dir}" />
    <arg value="-I" />
    <arg value="${android-jar}" />
    <arg value="${out-package}" />
    <!-- Same as package-res-and-assets, but without "-A ${asset-dir}" -->
    <target name="package-res-no-assets">
    <echo>Packaging resources...</echo>
    <exec executable="${aapt}" failonerror="true">
    <arg value="package" />
    <arg value="-f" />
    <arg value="-c" />
    <arg value="-M" />
    <arg value="AndroidManifest.xml" />
    <arg value="-S" />
    <arg value="${resource-dir}" />
    <!-- No assets directory -->
    <arg value="-I" />
    <arg value="${android-jar}" />
    <arg value="${out-package}" />
    <!-- Invoke the proper target depending on whether or not
    an assets directory is present. -->
    <!-- TODO: find a nicer way to include the "-A ${asset-dir}" argument
    only when the assets dir exists. -->
    <target name="package-res">
    <available file="${asset-dir}" type="dir" property="res-target" value="and-assets" />
    <property name="res-target" value="no-assets" />
    <antcall target="package-res-${res-target}" />
    <!-- Put the project's .class files into the output package file. -->
    <target name="package-java" depends="compile, package-res">
    <echo>Packaging java...</echo>
    <jar destfile="${out-package}"
    update="true" />
    <!-- Put the project's .dex files into the output package file.
    Use the zip command, available on most unix/Linux/MacOS systems,
    to create the new package (Ant 1.7 has an internal zip command,
    however Ant 1.6.5 lacks it and is still widely installed.)
    <target name="package-dex" depends="dex, package-res">
    <echo>Packaging dex...</echo>
    <exec executable="${zip}" failonerror="true">
    <arg value="-qj" />
    <arg value="${out-package}" />
    <arg value="${intermediate-dex}" />
    <!-- Create the package file for this project from the sources. -->
    <target name="package" depends="package-dex" />
    <!-- Create the package and install package on the default emulator -->
    <target name="install" depends="package">
    <echo>Sending package to default emulator...</echo>
    <exec executable="${adb}" failonerror="true">
    <arg value="install" />
    <arg value="${out-package}" />



Share This Page