开发者

Android.App.Activity - package does not exist

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]                       ^
 开发者_如何学C       [javac] /Users/admin/Downloads/moshe-5/src/ti/moshe/CustomAdapter.java:9: package android.graphics does not exist
        [javac] import android.graphics.Color;


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.


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.


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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜