I am working on an ant build file (stand alone from eclipse) to build my android application.
I need to generate the R.java file. I have done so successfully, however, when it tries to build my project from the src
directory it complains that it cannot find the imported R.java file. I see it in the gen
directory... but it still will not build.
It fails in the build-project
target. Fails saying that it "cannot find symbol" and it is reffering to the R.java file. And the line of code it is pointing at is the import line.
Here is my xml file, please assist, thank you! Let me know if you need more information.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="build" name="ATB">
<target name="init">
<mkdir dir="../bin/classes"/>
<copy includeemptydirs="false" todir="../bin/classes">
<fileset dir="../src">
<exclude name="**/*.java"/>
</fileset>
</copy>
<copy includeemptydirs="false" todir="../bin/classes">
<fileset dir="../gen">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target depends="clean" name="cleanall"/>
<target depends="resource-src,build-subprojects,build-project,jar" name="build"/>
<target name="build-subprojects"/>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true"
debuglevel="${debuglevel}"
destdir="../bin/classes"
source="${source}"
target="${target}"
executable="${env.JAVAHOME}/javac"
fork="true"
>
<src path="../src"/>
<classpath refid="ATB.classpath"/>
</javac>
<javac
debug="true"
debuglevel="${debuglevel}"
destdir="../bin/classes"
source="${source}"
target="${target}"
executable="${env.JAVAHOME}/javac"
fork="true"
>
<src path="../gen"/>
<classpath refid="ATB.classpath"/>
</javac>
</target>
<target depends="init" name="jar">
<jar destfile="../bin/${ant.project.name}">
<fileset dir="../src/">
</fileset>
</jar>
</target>
<target name="resource-src" description="Generate the R.java file for this project's resources.">
<exec executable="${aapt}" failonerror="true">
<arg value="package"/>
<arg value="-f"/>
<arg value="-v"/>
<arg value="-M"/>
<arg path="../AndroidManifest.xml"/>
<arg value="-A"/>
<arg path="../assets"/>
<arg value="-I"/>
<arg path="${android_jar}"/>
<arg value="-m"/>
<arg value="-J"/>
<arg path="../gen"/> <!-- Create R.java in the gen directory -->
<arg value="-S"/>
<arg path="../res"/>
</exec>
</target>
<target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects">
<ant antfile="build.xml" dir="${Comms.location}" inheritAll="false" target="clean"/>
<ant antfile="build.xml" dir="${Comms.location}" inheritAll="false" target="build"/>
</target>
</project>
Your script doesn't include {gen} path as compile source. Just add into
<javac>
: