NoClassDefFoundError develops library with Android application, Maven and Eclipse

I am developing an Android library ( SiriRestClient ), whose artifacts are managed through Maven, and I use Eclipse for development, I collect artifacts as a JAR file, since I have no assets in the project, only Java classes, and there are problems with packing artifacts like apklibs with Eclipse / Maven / ADT .

I am also developing an application for the Android user interface ( SiriRestClientUI ), which depends on the SiriRestClient library. I manage the SiriRestClient library dependency through Maven.

Both projects build and deploy perfectly independently in Eclipse.

PROBLEM:

Since I started managing the SiriRestClientUI dependency on SiriRestClient library through Maven, if I have a library project and SiriRestClientUI that opens at the same time in Eclipse, I get a NoClassDefFoundError when I try to deploy the SiriRestClientUI application to the device.

For instance:

 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 serious annoyance during the simultaneous development of the library and the application, since the only workaround I found was to edit the library code, build the library project, close the library project and then execute the SiriRestClientUI application.

I think the problem is with how Eclipse / Maven handles Maven dependencies when the library project is open.

Here is 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 in the "Maven Dependencies" section, which is pulled from my local Maven repository, and this is what I want. In this configuration, everything is working fine.

However, when I OPEN the SiriRestClient library project, my "Maven Dependencies" entries change and the JAR file disappears and the project folder is displayed instead:

enter image description here

If I try to start SiriRestClientUI when both projects are open, I get a NoClassDefFoundError . Thus, it seems that Eclipse redirects the assembly of the project, and the library classes are not included.

QUESTION:

How to configure Eclipse / Maven so that it always relies on a 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 NoClassDefFoundError with this configuration?

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

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

+4
source share
2 answers

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

+5
source

you need to make sure two things, firstly: it depends on the android object, there must be a node apklib, like this, don't forget the node packaging

 <modelVersion>4.0.0</modelVersion> <groupId>cn.company.common</groupId> <artifactId>util</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>apklib</packaging> <name>util</name> 

second: the dependencies of the node project on the android project, and do not forget the type of node, do not forget to add

 <dependency> <groupId>cn.company.common</groupId> <artifactId>util</artifactId> <version>0.0.1-SNAPSHOT</version> <type>apklib</type> </dependency> 
0
source

Source: https://habr.com/ru/post/1443526/


All Articles