Anm
Anm

Reputation: 3361

Android: How to reference a library project from an Eclipse ADT application project?

I have a project that is compiles but throws a NoClassDefFoundError on a classname included from a sibling library project, but only when built from Eclipse. When I build the project from the ant file, it runs just fine.

How do I tell the Eclipse build system that my application's .apk needs a copy of the .class files from the library project.

This page... http://developer.android.com/guide/developing/eclipse-adt.html#libraryReference makes is sound like adding the library should "just work" with no other steps. And I see it has updated my default.properties with the necessary link that makes my ant build work.

Despite following those steps (my library project is listed in the Android page of my application's project properties), Eclipse doesn't recognize the new classes in the editor. So I did the standard Eclipse step of adding the library to the Java Build Path. Now the compiler and IDE recognize the class, but my app still crashes with NoClassDefFoundError, even after checking the library in the Java Build Path, Order and Export.

What step am I missing?

Some background... I built the Eclipse project first. Then, in a separate directory, I used android create project ... with all the parameters to create an identically configured project. Finally, I copied the ant build.xml and *.properties files to the Eclipse project directory. I did the same thing with the library project I'm trying to reference.

Upvotes: 3

Views: 10227

Answers (4)

Girish K Gupta
Girish K Gupta

Reputation: 300

I got similar a issue. Even after adding a library project the required files were not included. It seems there is a bug as discussed in this thread.

I found that in Eclipse's default.properties file the library project location was not being read because my working project was in a different drive than library project (I was doing the development in Windows). After moving my project to same drive as library project it started working. This might work as a work around till the bug is fixed.

Upvotes: 0

Udit Jain
Udit Jain

Reputation: 1

1) Right click on your Android project.

2) Go to its properties

3) Choose Android option from the menu displayed on the left

4) See the library panel which is on the right side, below the list of APIs.

5) Click the "Add.." button to add the library project.

Keep in mind that the seperate project you are trying to add as a ibrary for your current project should be marked as "IsLibrary".

Upvotes: 0

Roger Heim
Roger Heim

Reputation: 11

We had the same issue (worked in IntelliJ and with Ant but not with Eclipse.) There was an installation of Aptana Studio installed in Eclipse. Removing that allowed the library project reference to work in Eclipse as advertised.

Upvotes: 1

djohns505
djohns505

Reputation: 216

I have this every once in a while and not sure what causes it. To fix this, I have to link to the source of my library projects. In the build path of your main project, link to the "src" folder of your library project that you are trying to include.

Upvotes: 1

Related Questions