views:

204

answers:

2

Hi all, I'm trying to set up an Android application with an Android library project dependence in Eclipse. I've set up a project called AnTest and a library project called AnLib. I've provided a reference to AnLib in the project properties of AnTest. Now I'm trying to refer to some library code (a static public method) from AnTest. Eclipse throws "com.anlib.Hello cannot be resolved to a type".

And it's not that the reference is dangling - I can see the resources properly merged. But from within AnTest, the only class in package com.anlib is "R".

Please, what am I doing wrong? Some very basic step must be missing...

EDIT: I've added AnLib to the Java build path/Projects in AnTest project properties. Now it compiles, but running throws a NoClassDefFoundError exception...

A: 

I have this set-up, but without resources in the "library" project. My main project is an Android project, but the "library" one is just a standard Java project. This seems to work well.

Under the build path ("Projects" tab) for the main Android project I have added the library project.

The library project's .project file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>DataExchange</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.wst.common.project.facet.core.builder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.wst.validation.validationbuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
        <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
        <nature>org.eclipse.jdt.core.javanature</nature>
        <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
    </natures>
</projectDescription>

The Android project's .project file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>Project</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>com.android.ide.eclipse.adt.ApkBuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
        <nature>org.eclipse.jdt.core.javanature</nature>
    </natures>
</projectDescription>

I don't remember doing anything special beyond that in setting this up.

ydant
Sorry, this is not relevant to my situation. I want both resources and code to merge.
Seva Alekseyev
Is there somewhere that it was indicated this should work? In Eclipse, I only see references to Android project, which appears to be intended a full fledged project not a library. If you have a link to a page or project which mentions/does this, it might help us troubleshoot.
ydant
Here: http://developer.android.com/intl/de/guide/developing/eclipse-adt.html#libraryProject My ADT is apparently new enough; I can set the "Is a library" checkbox and establish dependencies. Eclipse Ganymede, in case that matters.
Seva Alekseyev
+2  A: 

After carefully looking at the sample projects (TicTacToe), I've noticed a little something under classpath. It's a linked folder to the library sources. Project properties of the app, Java build path, under "Source" click "Link source", provide a path to the library\src.

There's no magic after all.

EDIT: the NDK (JNI-based, native) libraries are not picked up by default, either. Gotta establish a linked folder called "libs" to the respective libs in the library project.

EDIT2: the behavior of native libraries seems to depend on the version of ADT and/or Eclipse. Also assets are not merged, but this latter bit is actually documented.

Seva Alekseyev
thank you very much, this info can't be found anywhere !...
kosokund