39

I have an Android project in Eclipse I would like to convert to be built with Ant instead.

How can I achieve this? I have tried exporting an Ant build file but I'm pretty sure that's not going to work (nor does it when running ant with the exported file). I do not know much about Ant either so some explanation would also help.

EDIT: now I seem to have managed to create the needed build file but I need to add the projects libs like admob.jar to be seen by ant and used to build. as I am getting the following error

        -dex:
     [echo] Converting compiled files and external libraries into C:\Users\Jason
\Documents\Programming\Android\Android SVN\trunk\GPSAlarm\BusSnooze\bin\classes.
dex...
    [apply]
    [apply] UNEXPECTED TOP-LEVEL EXCEPTION:
    [apply] com.android.dx.util.ExceptionWithContext
    [apply]     at com.android.dx.util.ExceptionWithContext.withContext(Exceptio
nWithContext.java:46)
    [apply]     at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslato
r.java:340)
    [apply]     at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.ja
va:131)
    [apply]     at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.jav
a:85)
    [apply]     at com.android.dx.command.dexer.Main.processClass(Main.java:297)

    [apply]     at com.android.dx.command.dexer.Main.processFileBytes(Main.java:
276)
    [apply]     at com.android.dx.command.dexer.Main.access$100(Main.java:56)
    [apply]     at com.android.dx.command.dexer.Main$1.processFileBytes(Main.jav
a:228)
    [apply]     at com.android.dx.cf.direct.ClassPathOpener.processArchive(Class
PathOpener.java:245)
    [apply]     at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPath
Opener.java:130)
    [apply]     at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpe
ner.java:108)
    [apply]     at com.android.dx.command.dexer.Main.processOne(Main.java:245)
    [apply]     at com.android.dx.command.dexer.Main.processAllFiles(Main.java:1
83)
    [apply]     at com.android.dx.command.dexer.Main.run(Main.java:139)
    [apply]     at com.android.dx.command.dexer.Main.main(Main.java:120)
    [apply]     at com.android.dx.command.Main.main(Main.java:87)
    [apply] Caused by: java.lang.NullPointerException
    [apply]     at com.android.dx.cf.code.ConcreteMethod.<init>(ConcreteMethod.j
ava:84)
    [apply]     at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslato
r.java:243)
    [apply]     ... 14 more
    [apply] ...while processing <init> ()V
    [apply] ...while processing com/google/android/apps/analytics/AnalyticsRecei
ver.class
    [apply]
    [apply] 1 error; aborting
Jonik
  • 80,077
  • 70
  • 264
  • 372
Jason
  • 4,034
  • 4
  • 40
  • 62

3 Answers3

55

Running android update project -p . on the command line, in the base folder of your project will create the necessary build.xml and supporting files for an Ant build.

Christopher Orr
  • 110,418
  • 27
  • 198
  • 193
  • 3
    hmm seemed to get somewhere but there are many many compile errors about classes not implementing methods and stuff. while the code compiles and works perfectly from eclipse – Jason Dec 15 '10 at 20:42
  • 1
    Same issue as Jason, this works in most cases but not with all of my projects – Nathan Schwermann Mar 07 '13 at 06:18
  • It has generated local.properties and this message "build.xml: Found version-tag: custom. File will not be updated." When ant.properties will be generated ?? I want to change that file – KK_07k11A0585 Feb 25 '15 at 10:29
8

You can create ant build file directly from eclipse it self.. From File Menu

Here are the steps to create build.xml for any project in eclipse

File -> Export -> General -> Ant Buildfiles and choose required project to create a build file.

Ramesh Bugatha
  • 1,162
  • 1
  • 11
  • 24
1

While there may be no "Run Configuration to Ant" feature you can still open the run configuration and view the settings.

The Android Developers site has a section on using "Other IDEs"; here they cover a little on using Ant to compile if you're familiar with Ant already.

John Giotta
  • 16,432
  • 7
  • 52
  • 82
  • Yea but the build.xml file they keep speaking of does not exist – Jason Dec 15 '10 at 19:58
  • You generate the build.xml file in the "Creating an Android Project" step: http://developer.android.com/guide/developing/other-ide.html#CreatingAProject . It does more than you need if you already have a project, but you could do it and then just grab the build.xml file it gives you and use that as your starting point. – Cheryl Simon Dec 15 '10 at 20:07
  • @Mayra so I can use the android create project command on an already existing project? – Jason Dec 15 '10 at 20:22
  • Probably not, but as I said you can use it to create a similar project (same name, namespace, etc), and then grab the relevant files (build.xml) and move them into your existing project. – Cheryl Simon Dec 15 '10 at 20:33