Android SDK Tools r15 ant building problems

Nov
16

After an update in the Android SDK Manager I find myself with Android SDK Tools r15 and my ant build stopped working saying:

BUILD FAILED
/Users/me/myproject/android/build.xml:37: The following error occurred while executing this line:
/Users/me/android/tools/ant/pre_setup.xml:4: Your build.xml file is outdated. Delete it and regenerate it with 'android update

Aah right, let's update the project

$ android update project -p .
Updated local.properties
Exception in thread "main" java.lang.NullPointerException
	at com.android.sdklib.internal.project.ProjectProperties.parsePropertyFile(ProjectProperties.java:385)
	at com.android.sdklib.internal.project.ProjectProperties.load(ProjectProperties.java:229)
	at com.android.sdklib.internal.project.ProjectCreator.updateProject(ProjectCreator.java:605)
	at com.android.sdkmanager.Main.updateProject(Main.java:693)
	at com.android.sdkmanager.Main.doAction(Main.java:273)
	at com.android.sdkmanager.Main.run(Main.java:119)
	at com.android.sdkmanager.Main.main(Main.java:102)

Euhh ok, let's create a new project

./android create project --package com.domain.myproject --activity MyProject --target 8 --path ~/myproject2

Open the build.xml in the new project, add our own targets and stuff and copy it to the old project.
Also, some propertie files have a new name;

mv default.properties project.properties
mv build.properties ant.properties

Run ant.... Joy!!! fresh errors!!!

BUILD FAILED
/Users/me/android/tools/ant/build.xml:466: Invalid file: /Users/me/android/examples/GreenDroid-GoogleAPIs/build.xml

A third party project I use doesn't have a build.xml.... Why did it work in the past?
Ok, tinkering around I found it working again by coping build.xml and local.properties to the third party project.

Yihah running again, oops dex

-dex:
      [dex] Converting compiled files and external libraries into /Users/me/myproject/android/bin/classes.dex...
       [dx] 
       [dx] UNEXPECTED TOP-LEVEL EXCEPTION:
       [dx] java.lang.IllegalArgumentException: already added: Lgreendroid/app/ActionBarActivity;
       [dx] 	at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
       [dx] 	at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
       [dx] 	at com.android.dx.command.dexer.Main.processClass(Main.java:486)
       [dx] 	at com.android.dx.command.dexer.Main.processFileBytes(Main.java:455)
       [dx] 	at com.android.dx.command.dexer.Main.access$400(Main.java:67)
       [dx] 	at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:394)
       [dx] 	at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
       [dx] 	at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
       [dx] 	at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
       [dx] 	at com.android.dx.command.dexer.Main.processOne(Main.java:418)
       [dx] 	at com.android.dx.command.dexer.Main.processAllFiles(Main.java:329)
       [dx] 	at com.android.dx.command.dexer.Main.run(Main.java:206)
       [dx] 	at com.android.dx.command.dexer.Main.main(Main.java:174)
       [dx] 	at com.android.dx.command.Main.main(Main.java:95)
       [dx] 1 error; aborting

BUILD FAILED
/Users/me/android/tools/ant/build.xml:729: The following error occurred while executing this line:
/Users/me/android/tools/ant/build.xml:731: The following error occurred while executing this line:
/Users/me/android/tools/ant/build.xml:743: The following error occurred while executing this line:
/Users/me/android/tools/ant/build.xml:249: null returned: 1

Googling around it seems a common problem, created by multiple classes with the same name hanging around.
Let's find them using something like

find /Users/me/android/ -name ActionBarActivity*

And delete them with something like

rm -rf /Users/me/android/examples//GreenDroid-GoogleAPIs/bin/classes/greendroid

Be carefull with rm -rf!!! hitting enter accidentally, while tabbing to the path can be painfull o_O

Sweet!!! everything is running again, why am I running ant?
Well basically I was tired of copying keys around between test and release builds, so I used this excellent idea http://blog.cuttleworks.com/2011/02/android-dev-prod-builds/
and discovered ant made a ready to upload apk, with al the signing and aligning done!