Using Android build.xml in eclipse?

22.3k Views Asked by At

I have an android project which has an Ant buildfile. It works great via the command-line:

rascher@coltrane:~/git/$ ant
Buildfile: build.xml
    [setup] Android SDK Tools Revision 8
    [setup] Project Target: Android 2.1-update1
    [setup] API level: 7
    [setup] 

    ... etc etc etc ...

But when I try to use this in eclipse, build.xml has a red-X.

<?xml version="1.0" encoding="UTF-8"?>
<project name="MyWonderfulProject" default="help">

<project is underlined with the error: Default target help does not exist in this project

It seems like everybody else on the internet has this issue, and it seems to be caused by the fact that build.xml is using directives that come from the multiple nested android-specific files that this buildfile imports.

I have other projects in my workspace that use Eclipse's build mechanism, so I know that my environment is able to compile, run, and deploy Android applications without an issue. But this buildfile is giving me headaches.

What is the fix?

6

There are 6 best solutions below

1
On

If your build.xml has its own help target rather than relying on the imported one, then you need to put that target before the line

<taskdef name="setup" classname="com.android.ant.SetupTask" classpathref="android.antlibs" />
1
On

There is one target called 'help' defined in the ${sdk.dir}/tools/ant/main_rules.xml like below,

<target name="help">

    <echo>Android Ant Build. Available targets:</echo>
    <echo>   help:      Displays this help.</echo>
    <echo>   clean:     Removes output files created by other targets.</echo>
    <echo>   compile:   Compiles project's .java files into .class files.</echo>
    <echo>   debug:     Builds the application and signs it with a debug key.</echo>
    <echo>   release:   Builds the application. The generated apk file must be</echo>
    <echo>              signed before it is published.</echo>
    <echo>   install:   Installs/reinstalls the debug package onto a running</echo>
    <echo>              emulator or device.</echo>
    <echo>              If the application was previously installed, the</echo>
    <echo>              signatures must match.</echo>
    <echo>   uninstall: Uninstalls the application from a running emulator or</echo>
    <echo>              device.</echo>
</target>

copy this one to your build.xml and it should works.

0
On

I has same issue and all i did was goto on the eclipse

Window->Preferences->Ant->Editor->Problems

and click

Ignore All Build File Problems.
0
On

This isn't really an answer, but for what it's worth, I was able to make the problem go away by removing the eclipse project from the workspace, deleting .* in my project directory and starting over. Eclipse FTW!

6
On

Option 1:

Import the Android ant template file in the build.xml file. Assuming you have sdk.dir defined in local.properties and pointing to your Android installation directory, add the following under the project element:

    <import file="${sdk.dir}/platforms/${target}/templates/android_rules.xml" />

Option 2:

To actually use the Android ant targets in the Eclipse ant perspective, the above will not help. There seems to be some general level incompatibility that I haven't figured out to resolve completely, but to get things working at a satisfactory level though you can:

  • Import the project build.xml as a a builder. Project properties -> Builders -> import.
  • Do not use option 1. Instead ignore the warning about the missing template. Global properties -> Ant -> Editor -> Problems. Add build.xml to names.

This will have an impact on all projects and ignore actual errors, so it's not a perfect solution. But you can use the Android build options inside Eclipse, as well as from the command line.

2
On

This doesn't fix the problem, but it will make Eclipse stop getting in your way. Go to Window > Preferences > Ant > Editor, and select the Problems tab. Check the ignore all buildfile problems box.