Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Android build.xml in eclipse?

Tags:

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?

like image 583
poundifdef Avatar asked Feb 27 '11 20:02

poundifdef


People also ask

What is build XML in Android?

Apache ANT is tool to automate build of java projects ,by providing instructions in build. xml file ,eclipse uses ant to build projects . I suggest Android Studio as IDE which uses Gradle for build of android project and that is officially supported by google.

How do I open Ant build in Eclipse?

Open the Java project in Eclipse. Right click the project. Go to Export. In the General section select Ant build files and click "Next"


2 Answers

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.

like image 111
Tatu Lahtela Avatar answered Sep 18 '22 17:09

Tatu Lahtela


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.

like image 22
len Avatar answered Sep 20 '22 17:09

len