Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

building android app with ant only

Tags:

android

ant

I'm trying to build simple android project by means of ant. Here is my ant script

<?xml version="1.0" encoding="UTF-8"?>
    <project name="HelloWorld" default="help">

    <!-- Input directories -->
    <property name="source.dir" value="src" />
    <property name="source.absolute.dir" location="${source.dir}" />
    <property name="gen.dir" value="gen" />
    <property name="gen.absolute.dir" location="${gen.dir}" />
    <property name="resource.dir" value="res" />
    <property name="resource.absolute.dir" location="${resource.dir}" />
    <property name="asset.dir" value="assets" />
    <property name="asset.absolute.dir" location="${asset.dir}" />

    <!-- Directory for the third party java libraries -->
    <property name="external.libs.dir" value="libs" />
    <property name="external.libs.absolute.dir" location="${external.libs.dir}" />

    <!-- Output directories -->
    <property name="out.dir" value="ant"/>
    <property name="out.absolute.dir" location="${out.dir}/bin"/>
    <property name="out.classes.absolute.dir" value="${out.absolute.dir}/classes"/>

    <property name="sdk.dir" value="../../AndroidSDK"/>
    <property name="sdk.absolute.dir" location="${sdk.dir}"/>

    <property name="android.jar" value="${sdk.absolute.dir}/platforms/android-8"/>

    <!-- The final package file to generate -->
    <property name="out.debug.unaligned.package"
                  location="${out.absolute.dir}/${ant.project.name}-debug-unaligned.apk" />
    <property name="out.debug.package"
                  location="${out.absolute.dir}/${ant.project.name}-debug.apk" />
    <property name="out.unsigned.package"
                  location="${out.absolute.dir}/${ant.project.name}-unsigned.apk" />
    <property name="out.unaligned.package"
                  location="${out.absolute.dir}/${ant.project.name}-unaligned.apk" />
    <property name="out.release.package"
                  location="${out.absolute.dir}/${ant.project.name}-release.apk" />

    <!-- Verbosity -->
    <property name="verbose" value="true" />

    <condition property="v.option" value="-v" else="">
        <istrue value="${verbose}" />
    </condition>

    <!-- tools location -->
    <property name="android.tools.dir" location="${sdk.absolute.dir}/tools" />
    <property name="android.platform.tools.dir" location="${sdk.absolute.dir}/platform-tools" />
    <condition property="exe" value=".exe" else=""><os family="windows" /></condition>
    <condition property="bat" value=".bat" else=""><os family="windows" /></condition>
    <property name="adb" location="${android.platform.tools.dir}/adb${exe}" />
    <property name="zipalign" location="${android.tools.dir}/zipalign${exe}" />
    <property name="aidl" location="${android.platform.tools.dir}/aidl${exe}" />
    <property name="aapt" location="${android.platform.tools.dir}/aapt${exe}" />
    <property name="dx" location="${android.platform.tools.dir}/dx${bat}" />

    <!-- Generates the R.java file for this project's resources. -->
    <target name="resource-src" depends="dirs">
        <echo>Generating R.java, Manifest.java from the resources...</echo>
        <exec executable="${aapt}" failonerror="true">
            <arg value="package" />
            <arg line="${v.option}" />
            <arg value="-m" />
            <arg value="-J" />
            <arg path="${gen.absolute.dir}" />
            <arg value="-M" />
            <arg path="AndroidManifest.xml" />
            <arg value="-S" />
            <arg path="${resource.absolute.dir}" />
            <arg value="-I" />
            <arg path="${android.jar}" />
        </exec>
    </target>

    <!-- Generates java classes from .aidl files. -->
    <target name="aidl" depends="dirs">
        <echo>Compiling aidl files into Java classes...</echo>
        <apply executable="${aidl}" failonerror="true">
            <arg value="-p${android.aidl}" />
            <arg value="-I${source.absolute.dir}" />
            <arg value="-o${gen.absolute.dir}" />
            <fileset dir="${source.absolute.dir}">
                <include name="**/*.aidl" />
            </fileset>
        </apply>
    </target>

    <target name="compile" depends="resource-src, aidl" description="Compiles project's .java files into .class files">
        <javac destdir="${classes.absolute.dir}" >
            <src path="${source.absolute.dir}" />
            <src path="${gen.absolute.dir}" />

            <classpath>
                <fileset dir="${external.libs.absolute.dir}" includes="*.jar" />
            </classpath>
        </javac>
    </target>

    <target name="clean" description="Removes output files created by other targets.">
        <delete dir="${out.absolute.dir}" verbose="${verbose}" />
        <delete dir="${gen.absolute.dir}" verbose="${verbose}" />
    </target>

    <!-- Creates the output directories if they don't exist yet. -->
    <target name="dirs">
        <echo>Creating output directories if needed...</echo>
        <mkdir dir="${resource.absolute.dir}" />
        <mkdir dir="${external.libs.absolute.dir}" />
        <mkdir dir="${gen.absolute.dir}" />
        <mkdir dir="${out.absolute.dir}" />
        <mkdir dir="${out.classes.absolute.dir}" />
    </target>

</project>

This script fails on code block <target name="resource-src" depends="dirs"> and I get such messages: Configurations:D:\Development\Eclipse_workspace\HelloWorld\res\values\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Light' D:\Development\Eclipse_workspace\HelloWorld\res\values-v11\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Holo.Light'. D:\Development\Eclipse_workspace\HelloWorld\res\values-v14\styles.xml:8: error: Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Holo.Light.DarkActionBar'.

If I build the app using eclipse - it's OK, app is built fine.

So, what is wrong? How can I fix it?

like image 470
konunger Avatar asked Jan 24 '13 18:01

konunger


1 Answers

you are doing it that hard way. android has tools to create ant build scripts for your project. just run this from your project folder,

android update project --path .

(the android command is in <sdk folder>/tools).

this will create a build.xml and several other accompanying properties files. for detailed usage of the android command, see the documentation on managing projects from the command line.

like image 72
Jeffrey Blattman Avatar answered Sep 28 '22 02:09

Jeffrey Blattman