8

I got an andorid project files that are supposed to compile correctly.

I installed the latest eclipse and Andriod ADT plugins.

I then imported the project and right clicked build.xml to run as ANT build. but I got erors on some basic code which I am sure is originating from my misconfigured setup.

I also tried to run it using ANT from the command line. both times I got the same type of errors

What is wrong ?

    Buildfile: /Users/admin/Downloads/moshe-5/build.xml
    init:
    process.annotations:
        [javac] Compiling 9 source files to /Users/admin/Downloads/moshe-5/build/classes
        [javac] /Users/admin/Downloads/moshe-5/src/ti/moshe/CustomAdapter.java:7: package android.app does not exist
        [javac] import android.app.Activity;
        [javac]                   ^
        [javac] /Users/admin/Downloads/moshe-5/src/ti/moshe/CustomAdapter.java:8: package android.content does not exist
        [javac] import android.content.Context;
        [javac]                       ^
        [javac] /Users/admin/Downloads/moshe-5/src/ti/moshe/CustomAdapter.java:9: package android.graphics does not exist
        [javac] import android.graphics.Color;
Moshe Marciano
  • 2,349
  • 4
  • 33
  • 44

5 Answers5

3

In my case, it was due to the problem that I didn't have a default.properties file with the target field in it.

I had to manually create the file and put

target=android-9

Or other Android target version.

If you run

ant -v

with your build command, you'll probably see this line

Property "target" has not been set

and

[property] Unable to find property file: /PATH_TO/default.properties

Those messages are enough hints.

Hope this solves your problem too.

kakyo
  • 10,460
  • 14
  • 76
  • 140
1

It is not finding the android packages. IN the build step you should include android.jar corresponding to the android version you want to port to.

potter
  • 281
  • 1
  • 3
  • OK, I found the missing configuration settings in the build.properties files. now it compiles ok. but it won't run. I dont have run as android menu. and no way to run the app in the Android emulator from eclipse – Moshe Marciano Sep 01 '11 at 05:59
1

When you write your compile target, you are overriding the default one given by android_rules.xml     located in:   C:\Program Files (x86)\Android\android-sdk\platforms\android-8\templates or wherever android_rules.xml is located on your computer.

Like Potter mentioned above it is not finding the android library and other libraries, so please look at android_rules.xml to see how it sets up the proper libraries:

<target name="compile" depends="-resource-src, -aidl"
            description="Compiles project's .java files into .class files">
    <!-- If android rules are used for a test project, its classpath should include
         tested project's location -->
    <condition property="extensible.classpath"
                       value="${tested.project.absolute.dir}/bin/classes" else=".">
        <isset property="tested.project.absolute.dir" />
    </condition>
    <condition property="extensible.libs.classpath"
                       value="${tested.project.absolute.dir}/libs" else="./libs">
        <isset property="tested.project.absolute.dir" />
    </condition>
    <javac encoding="ascii" target="1.5" debug="true" extdirs=""
            destdir="${out.classes.absolute.dir}"
            bootclasspathref="android.target.classpath"
            verbose="${verbose}" classpath="${extensible.classpath}">
        <src path="${source.absolute.dir}" />
        <src path="${gen.absolute.dir}" />
        <classpath>
            <fileset dir="${external.libs.absolute.dir}" includes="*.jar" />
            <fileset dir="${extensible.libs.classpath}" includes="*.jar" />
        </classpath>
   </javac>
</target>

Inside the classpath tags is where android.jar is included. You can add other libraries by adding more filesets

Some other good examples of code for writing the ANT compile target are:

Can't build and run an android test project created using "ant create test-project" when tested project has jars in libs directory <-- this worked for me

http://www.vogella.de/articles/ApacheAnt/article.html

http://www.alittlemadness.com/2010/05/31/setting-up-an-android-project-build/ <-- setting up ANT project

Community
  • 1
  • 1
pronewby
  • 11
  • 1
0

It's most likely not finding Android because you didn't define the sdk.dir property, which tells the build process where to find Android. This property is usually in a local.properties file and is populated when you do:

android update project

as described here:

http://developer.android.com/tools/projects/projects-cmdline.html#UpdatingAProject

Christopher Perry
  • 38,891
  • 43
  • 145
  • 187
-8

Don't bother building using ANT. Eclipse and the ADT plugin provide excellent tool to save you the trouble. Simply right click the project, choose run as -> Android application

IncrediApp
  • 10,303
  • 2
  • 33
  • 24
  • there is no run as android app, see the screenshot http://cl.ly/3A3X3p0f3A2i1x1W2K31 – Moshe Marciano Aug 31 '11 at 22:09
  • Is the project you created an Android project? If the project you imported wasn't originally an Eclipse project, then it probably isn't. IIRC the context menu should have a option Android > Convert to Android project (or similar). – RoToRa Aug 31 '11 at 23:53
  • well.. I can't find a convert menu like that. but I followed this link http://enarion.net/programming/eclipse-change-general-to-java-project/ and checked my .project file which has the correct nature org.eclipse.jdt.core.javanature – Moshe Marciano Sep 01 '11 at 05:54
  • I tried command line : ant run emulator and got Target "emulator" does not exist in the project – Moshe Marciano Sep 01 '11 at 06:01
  • Ok, I misremembered, that one could convert a Java project to a Android project. Have you tried to create a new Android project and import your project into that? – RoToRa Sep 01 '11 at 12:34
  • No, I have very little experience with eclipse, I will try to find it. if you recall how I'll appreciate an explanation – Moshe Marciano Sep 01 '11 at 14:16
  • 21
    This is horrible advice, especially if you're trying to set up a continuous build using Jenkins etc. – Christopher Perry Jul 06 '12 at 16:58
  • 95% of the developers don't need to deal with anything other than the tools that come with Eclipse and ADT. The asker of this question was a newbie Android developer (from the looks of it) and has absolutely no reason to complicate things by using Ant. And I agree, if someone has the need for complex builds, Ant could be the solution. Yet, this wasn't the question – IncrediApp Jul 09 '12 at 16:00
  • 8
    @IncrediApp I would advise on learning how to build the project yourself, instead of relying on an IDE so you can learn how it actually works. Engineers are supposed to understand the systems they build. This answer doesn't answer his question, which is "what is wrong?" – Christopher Perry Jul 10 '12 at 00:48
  • 2
    So how far would an Android programmer need to go in order to develop an app? Maybe delve into the way Eclipse runs ANT scripts? Or maybe study the Dalvik VM and the way it works? I really think that you don't have to "understand the system" of such components, unless it's necessary for what you're doing or isn't helpful for what you're trying to achieve and needs a few tweaks to make it work. But I guess you won't agree with me so we'll agree to disagree on that. – IncrediApp Jul 11 '12 at 18:53