android (3)
ant (2)
beautifulsoup (1)
debian (1)
decorators (1)
django (9)
dovecot (1)
encryption (1)
fix (4)
gotcha (2)
hobo (1)
htmlparser (1)
imaplib (2)
java (1)
json (2)
kerberos (2)
linux (7)
lxml (5)
markdown (4)
mechanize (6)
multiprocessing (1)
mysql (2)
nagios (2)
new_features (3)
open_source (5)
optparse (2)
parsing (1)
perl (2)
postgres (1)
preseed (1)
pxe (4)
pyqt4 (1)
python (41)
raid (1)
rails (1)
red_hat (1)
reportlab (4)
request_tracker (2)
rt (2)
ruby (1)
scala (1)
screen_scraping (7)
shell_scripting (8)
soap (1)
solaris (3)
sql (2)
sqlalchemy (2)
tips_and_tricks (1)
twitter (2)
ubuntu (1)
vmware (2)
windows (1)
zimbra (2)

Google has put a lot of work into their Android platform, but their non-Eclipse development instructions could use some work. Just trying to build their Hello, Android fails if you follow their notes to the letter. You'll get this error or similar:

[tlesmann@kimiko HelloAndroid]$ ant
Buildfile: build.xml

     [echo] Creating output directories if needed...

     [echo] Generating / from the resources...

     [echo] Compiling aidl files into Java classes...

    [javac] Compiling 2 source files to /home/lethal/src/android/HelloAndroid/bin/classes
    [javac] Compliance level '1.4' is incompatible with target level '1.5'. A compliance level '1.5' or better is required

/home/tlesmann/src/android/HelloAndroid/build.xml:140: Compile failed; see the compiler error output for details.

Total time: 1 second

I was completely at a loss with this error and all the pages I found on Google were worthless. I'm hoping to change that with this post. The problem is that Sun's javac has a compliance level of 1.4 by default. This can be changed with a command-line argument of -1.5. To get ant to use this argument when compiling, you have to edit the build.xml like so:

<!-- 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=""
        <compilerarg value="-1.5"/>
            <fileset dir="${external-libs}" includes="*.jar"/>

Add the line, <compilerarg value="-1.5"/>, within the javac element and ant will properly build the Hello, Android application. I'm surprised that the activitycreator program does not do this for you as Google advises you to use Sun's JDK.

I hope I've helped you avoid the frustration I suffered solving this silly issue.

NOTE: You no longer have to do this with the release of the 1.5 SDK! Just install Sun's Java and it will build without a problem.

Posted by Tyler Lesmann on December 6, 2008 at 7:08 and commented on 3 times
Tagged as: android ant fix gotcha java