0

I've carefully followed the very clear advice given on this subject by Gunar at: Add a non-Android library project to an Android app in Eclipse but I still get class-not-defined errors. I'm using an ordinary Java desktop project (not an Android project) as the library and it is resident in Eclipse's workspace. My Android project can "see" classes and interfaces in the library project and it compiles and loads to the emulator but crashes as soon as a class or interface in the library project is referenced. I do not have a jar for the library project but thought that Eclipse/ADT would find it's source in the workspace. I'm obviously wrong.

Must I have the library project in jar form?

I have loaded the latest SDK tools etc in ADT.

Community
  • 1
  • 1
blagdonman
  • 41
  • 1
  • 4

1 Answers1

0

As I know you need create Android project from source code (aka desktop project source files) and remove Android library but set Android dependencies + JRE.

So your project should look like:

enter image description here

After that you can successfully create jar and add to classpath.

Maxim Shoustin
  • 77,483
  • 27
  • 203
  • 225
  • Thank you Maxim, but I still get the exception. Have tried building jar file for library project and adding it to Android project's classpath but still get exception. Could you please explain the reasoning underlying your suggestion as it is very different from other suggested fixes? – blagdonman Sep 23 '13 at 17:18
  • what Exception did you get? – Maxim Shoustin Sep 23 '13 at 17:44
  • java.lang.NoClassDefFoundError – blagdonman Sep 24 '13 at 13:28
  • go to Properties-> Java build path -> Order and Exports, selectet there checkbox with your jar – Maxim Shoustin Sep 24 '13 at 13:35
  • java.lang.NoClassDefFoundError This is a knock-on effect caused by not being able to find an interface that exists in the library project. – blagdonman Sep 24 '13 at 13:38
  • All the right stuff is chaecked. Just tried it all again and got same exception. – blagdonman Sep 24 '13 at 14:15
  • Have taken another approach: have attached library project's source files to the Android project. Probably not as convenient but it works. Thanks for your interest. – blagdonman Sep 27 '13 at 22:07