Hi all,  I have a library project (not external jar) as part of my
main Android project. This project is included in Eclipse via the
“Link Source” option. The library project contains its own source and
resource files. I want to automate the build via Ant.  I tried to use
android tools for updating a library project but received error : “no
resources specified”

Has anyone had experience including libraries and building via Ant? An
example would be appreciated.

This is the build file I am currently using:-

Build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="android_bundles" default="build">

    <!-- Properties -->
    <property file="private.properties" />

      <property name="sdk-location" value="${android-sdk}/platforms/$
{platform-version}"></property>
      <property name="android-tools" value="${sdk-location}/tools" />

      <path id="android.target.classpath">
            <pathelement path="${android-sdk}/tools/lib/*.jar"/>
            <pathelement path="${android-tools}/lib/*.jar"/>
      </path>

    <!-- Custom tasks -->
      <taskdef resource="net/sf/antcontrib/antlib.xml">
              <classpath>
                <pathelement location="${ant.home}/lib/ant-
contrib-1.0b3.jar"/>
              </classpath>
      </taskdef>
    <taskdef name="aaptexec"
        classname="com.android.ant.AaptExecLoopTask"
      classpath="${android-sdk}/tools/lib/anttasks.jar;${android-sdk}/
tools/lib/sdklib.jar" />
    <taskdef name="apkbuilder"
      classname="com.android.ant.ApkBuilderTask"
      classpath="${android-sdk}/tools/lib/anttasks.jar;${android-sdk}/
tools/lib/apkbuilder.jar;${android-sdk}/tools/lib/androidprefs.jar;$
{android-sdk}/tools/lib/jarutils.jar;${android-sdk}/tools/lib/
sdklib.jar" />

    <!-- folder for the 3rd party java libraries -->
    <property name="external-libs-folder"  value="${sdk-location}" /
>

    <property name="source-folder"         value="src" />
    <property name="resource-folder"       value="res" />
    <property name="asset-folder"          value="assets" />
    <property name="source-location"       value="${proj-dir}/${source-
folder}" />
      <property name="resource-location"     value="${proj-dir}/$
{resource-folder}" />
      <property name="asset-location"        value="${proj-dir}/$
{asset-folder}" />

    <!-- Output directories -->
    <property name="gen-folder"            value="gen" />
      <property name="gen-location"          value="${build-dir}/${gen-
folder}" />
    <property name="bin-location"          value="${build-dir}/bin" />
    <property name="out-classes"           value="classes" />
    <property name="out-classes-location"  value="${build-dir}/${out-
classes}"/>
    <property name="externallibs"            value="${proj-dir}/libs"/
>

    <!-- Intermediate files -->
    <property name="dex-file" value="classes.dex" />
    <property name="intermediate-dex" value="${bin-location}/${dex-
file}" />
    <!-- dx does not properly support incorrect / or \ based on the
platform
         and Ant cannot convert them because the parameter is not a
valid path.
         Because of this we have to compute different paths depending
on the platform. -->
    <condition property="intermediate-dex-location"
            value="${basedir}\${intermediate-dex}"
            else="${basedir}/${intermediate-dex}" >
        <os family="windows"/>
    </condition>

    <!-- The final package file to generate -->
    <property name="out-debug-unaligned-package" value="${bin-
location}/${app.name}-unaligned.apk"/>
    <property name="out-debug-package" value="${bin-location}/$
{app.name}-debug.apk"/>
    <property name="out-unsigned-package" value="${bin-location}/$
{app.name}-unsigned.apk"/>
    <property name="out-unaligned-package" value="${bin-location}/$
{app.name}-unaligned.apk"/>
    <property name="out-release-package" value="${out-folder}/$
{app.name}.apk"/>

    <!-- Tools -->
    <condition property="exe" value=".exe" else=""><os
family="windows"/></condition>
    <!-- Tools -->
    <property name="aapt" value="${android-tools}/aapt${exe}" />
    <property name="aidl" value="${android-tools}/aidl" />
    <!-- property name="dx" value="${android-tools}/lib/dx.jar" / -->

    <property name="tool-dx" value="${android-tools}/dx.bat" />

      <property name="tool-android" value="${android-sdk}/tools/
android.bat" />

    <!--property name="zip" value="zip" / -->
    <property name="android-jar" value="${sdk-location}/android.jar" /
>
      <property name="adb" value="${android-tools}/adb${exe}"/>
    <property name="zipalign" value="${android-sdk}/tools/zipalign$
{exe}" />

      <property name = "android-framework" value = "${sdk-location}/
framework.aidl"/>

    <!-- Clean old output directories -->
      <target name="clean-android">
            <delete dir="${resource-location}" />
            <delete dir="${gen-location}" />
            <delete dir="${bin-location}" />
            <delete dir="${out-classes-location}"/>
      </target>

      <!-- Create the output directories if they don't exist yet. -->
    <target name="dirs">
        <echo>Creating output directories if needed...</echo>
        <mkdir dir="${resource-location}" />
        <mkdir dir="${gen-location}" />
      <mkdir dir="${bin-location}" />
        <mkdir dir="${out-classes-location}" />
      <mkdir dir="${asset-folder}"/>
    </target>

      <!-- target name="merge-lib-project">
      <apply executable="${tool-android}" failonerror="true"
parallel="false" verbose="true">
            <arg value="update lib-project" />
            <arg value="/-/-target 9" />
            <arg value="/-/-path  ${proj-dir}" />
            <arg value="/-/-library  /Android-CallHandlerLibrary" />
      </apply>
      </target -->

    <!-- Generate 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>
      <!--echo>${aapt} package -m -J ${gen-location} -M ${proj-dir}/
AndroidManifest.xml -S ${resource-location} -I ${android-jar}</echo --
>
        <exec executable="${aapt}" failonerror="true">
            <arg value="package" />
            <arg value="-m" />
            <arg value="-J" />
            <arg path="${gen-location}" />
            <arg value="-M" />
            <arg path="${proj-dir}/AndroidManifest.xml" />
            <arg value="-S" />
            <arg path="${resource-location}" />
            <arg value="-I" />
            <arg path="${android-jar}" />
            <arg value="-v" />
        </exec>
    </target>

    <target name="sub-resource-src" depends="dirs">
        <echo>Generating R.java / Manifest.java from the resources...</
echo>
      <!--echo>${aapt} package -m -J ${gen-location} -M ${proj-dir}/
AndroidManifest.xml -S ${resource-location} -I ${android-jar}</echo --
>
        <exec executable="${aapt}" failonerror="true">
            <arg value="package" />
            <arg value="-m" />
            <arg value="-J" />
            <arg path="${gen-location}" />
            <arg value="-M" />
            <arg path="${proj-dir}/AndroidManifest.xml" />
            <arg value="-S" />
            <arg path="${resource-location}" />
            <arg value="-I" />
            <arg path="${android-jar}" />
        </exec>
    </target>

    <!-- Generate 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-framework}"/>
            <arg value="-I${source-location}" />
            <arg value="-o${gen-location}" />
            <fileset dir="${source-location}">
                <include name="**/*.aidl"/>
            </fileset>
        </apply>
    </target>

      <target name="res-src-aidl-prepare" depends="sub-resource-src,
aidl" />

    <!-- Compile this project's .java files into .class files. -->
    <target name="compile" depends="resource-src, aidl">
      <echo>Compile this project's .java files into .class files.</
echo>
      <echo>SUB-SRC : ${sub-source-location}</echo>
      <echo>SUB-GEN : ${sub-gen-location}</echo>
      <echo>javac </echo>
        <javac encoding="utf-8" target="1.6" debug="true" extdirs=""
                destdir="${out-classes-location}"
                bootclasspathref="android.target.classpath">
            <src path="${source-location}" />
            <src path="${gen-location}" />
            <!-- src path="${sub-source-location}" / -->
            <classpath>
                <fileset file="${android-jar}"/>
                  <fileset dir="${externallibs}"/>
            </classpath>
         </javac>
    </target>

    <!-- Convert this project's .class files into .dex files. -->
    <target name="dex" depends="compile">
      <echo>Converting compiled files and external libraries into $
{out-folder}/${dex-file}...</echo>
      <!-- java jar="${dx}" fork="true">
            <arg value="/-/-dex" />
            <arg value="/-/-output=${intermediate-dex-location}" />
            <arg path="${out-classes-location}" />
            <fileset dir="${externallibs}" includes="*.jar" />
      </java -->

      <apply executable="${tool-dx}" failonerror="true"
parallel="true">
            <arg value="--dex" />
            <arg value="--output=${intermediate-dex-location}" />
            <arg path="${out-classes-location}" />
            <fileset dir="${externallibs}" includes="*.jar" />
      </apply>
    </target>

    <!-- Put the project's resources into the output package file This
actually can create multiple resource package in case
         Some custom apk with specific configuration have been
declared in default.properties. -->
    <target name="package-resources">
        <echo>Packaging resources</echo>
        <aaptexec executable="${aapt}"
                command="package"
                manifest="${proj-dir}/AndroidManifest.xml"
                resources="${resource-location}"
                assets="${asset-location}"
                androidjar="${android-jar}"
                outfolder="${bin-location}"
                basename="${app.name}" />
    </target>

    <!-- Package the application and (maybe) sign it with a debug key.
         This requires the property sign.package to be set to true or
false. -->
    <target name="package">
        <apkbuilder
                outfolder="${bin-location}"
                basename="${app.name}"
                signed="false"
                verbose="true">
            <file path="${intermediate-dex}" />
            <jarfolder path="${externallibs}" />
            <!-- nativefolder path="${libs-folder}" / -->
        </apkbuilder>
    </target>

    <target name="release" depends="dex, package-resources, package">
        <!-- get passwords -->
        <!-- input
                message="Please enter keystore password (store:$
{key.store}):"
                addproperty="key.store.password"/>
        <input
                message="Please enter password for alias '$
{key.alias}':"
                addproperty="key.alias.password"/ -->
        <!-- sign the APK -->
        <echo>Signing final apk...</echo>
        <signjar
                jar="${out-unsigned-package}"
                signedjar="${out-unaligned-package}"
                keystore="${key.store}"
                storepass="${key.store.password}"
                alias="${key.alias}"
                keypass="${key.alias.password}"/>
        <!-- zip align the APK -->
        <echo>Running zip align on final apk...</echo>
        <exec executable="${zipalign}" failonerror="true">
            <arg value="-f" />
            <arg value="4" />
            <arg path="${out-unaligned-package}" />
            <arg path="${out-release-package}" />
        </exec>
        <echo>Release Package: ${out-release-package}</echo>
    </target>

      <target name="build" depends="release" />

</project>

Thanks,
Helena

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to