Search code examples
androideclipsemavenadtandroid-maven-plugin

NoClassDefFoundError developing library with Android app, Maven, and Eclipse


I'm developing an Android library (SiriRestClient) whose artifacts are managed via Maven, and I'm using Eclipse for development. I'm packaging the artifacts as a JAR file, since I don't have any assets in the project, only Java classes, and there are issues packaging artifacts as apklibs with Eclipse/Maven/ADT.

I'm also developing an Android user interface application (SiriRestClientUI) that depends on the SiriRestClient library. I'm managing the dependency on the SiriRestClient library via Maven.

Both project build and deploy fine independently in Eclipse.

THE PROBLEM:

Since I started managing the SiriRestClientUI dependency on the SiriRestClient library via Maven, if I have the library project and SiriRestClientUI open simultaneously in Eclipse, I get a NoClassDefFoundError when I try to deploy the SiriRestClientUI app to a device.

For example:

11-01 16:11:52.288: E/AndroidRuntime(9409): java.lang.NoClassDefFoundError: edu.usf.cutr.siri.android.client.config.SiriJacksonConfig
11-01 16:11:52.288: E/AndroidRuntime(9409):     at edu.usf.cutr.siri.android.ui.MainActivity.onCreate(MainActivity.java:100)
11-01 16:11:52.288: E/AndroidRuntime(9409):     at android.app.Activity.performCreate(Activity.java:4470)
11-01 16:11:52.288: E/AndroidRuntime(9409):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
11-01 16:11:52.288: E/AndroidRuntime(9409):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
11-01 16:11:52.288: E/AndroidRuntime(9409):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
11-01 16:11:52.288: E/AndroidRuntime(9409):     at android.app.ActivityThread.access$600(ActivityThread.java:128)
11-01 16:11:52.288: E/AndroidRuntime(9409):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
11-01 16:11:52.288: E/AndroidRuntime(9409):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-01 16:11:52.288: E/AndroidRuntime(9409):     at android.os.Looper.loop(Looper.java:137)
11-01 16:11:52.288: E/AndroidRuntime(9409):     at android.app.ActivityThread.main(ActivityThread.java:4514)
11-01 16:11:52.288: E/AndroidRuntime(9409):     at java.lang.reflect.Method.invokeNative(Native Method)
11-01 16:11:52.288: E/AndroidRuntime(9409):     at java.lang.reflect.Method.invoke(Method.java:511)
11-01 16:11:52.288: E/AndroidRuntime(9409):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
11-01 16:11:52.288: E/AndroidRuntime(9409):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
11-01 16:11:52.288: E/AndroidRuntime(9409):     at dalvik.system.NativeStart.main(Native Method)`

This is a major annoyance during the simultaneous development process of the library and the app, as the only workaround I've found is to edit the library code, build the library project, close the library project, and then execute the SiriRestClientUI app.

I think the issue stems from how Eclipse/Maven is handling the Maven dependencies when the library project is open.

Here's an Eclipse screenshot showing the SiriRestClientUI project, when the library project (SiriRestClient, above it) is CLOSED:

enter image description here

You can see the sirirestclient-1.0.0-SNAPSHOT.jar file under "Maven Depedencies," being pulled from my local Maven repository, which is what I want. Under this configuration, everything works fine.

However, when I OPEN the SiriRestClient library project, my "Maven Depedencies" entries change and the JAR file disappears, and instead a folder for the project is shown:

enter image description here

If I try to launch the SiriRestClientUI when both projects are open, then I get the NoClassDefFoundError. So, it seems that Eclipse is redirecting the project build and the library classes aren't being included.

THE QUESTION:

How can I configure Eclipse/Maven so that it always relies on the JAR file in the local Maven repository, instead of switching the Maven dependency to the local project?

Or, is there another way to get rid of the NoClassDefFoundError with this configuration?

The pom.xml file for the library project is here.

The pom.xml file for the SiriRestClientUI app project is here.


Solution

  • Try this: right click on the project -> Properties -> Maven -> uncheck Resolve dependencies from Workspace projects.