3

I'm currently trying to program an Android application. Yet I'm stuck because I'm trying in incorporate a Java library I've written myself. When I run a test code from a plain Eclipse (No Android) it works perfectly, but when I try to add it to my Android code it won't.

In my library project:
This project is a project that has a server + client connection using Java Sockets, I have written an API for the Server and Client to communicate, in Windows it works perfectly, yet it won't load my class: ClientAPI in Android :/
 I have exported my code as a JAR File. I checked the: Export generated class files & resources.
This project also incorporates an external library from LastFM api.

In my Android project:
I'm using ADT v22.0.1-685705
Using the Android 4.2.2 reference library
 I copied my library to the libs folder, I loaded the library in my build path and added it to the top my "Order and Export" list.

I have tried several permutations of including the library but without luck.
I tried:

  1. Add my library to 'libs' folder + build path
  2. Add my library + the LastFM library to 'libs' folder + build path
  3. Export my library as a runnable jar + the two above steps with that jar
  4. Copy the project to the same workspace and include the project instead of the library
  5. Above step but add the LastFM library seperatly

None of the above tries worked :/ I hope the java socket doesn't make it incompatible because it is essential to my program.

Marc Went
  • 144
  • 1
  • 13
  • Often when you add new library you have to do a Project -> Clean to force rebuild. Also check the jar for class X is indeed exist on your build classpath – gerrytan Jun 16 '13 at 23:58
  • @gerrytan I tried, yet it didn't work. I cleaned several times. The library is added to my classpath at the top of the list so in theory everything should work just fine :/ – Marc Went Jun 17 '13 at 00:04
  • Did you check if in Java Build Path - Order and Export the Android Private Libraries is checked? – Emanuel Moecklin Jun 17 '13 at 01:08
  • @EmanuelMoecklin I clearly stated in my question I did check everything I could find possibly online – Marc Went Jun 17 '13 at 07:17
  • Maybe you should explain what the actual problem is. Does it compile or not? Does it crash when you run it and if yes what exception do you get? – Emanuel Moecklin Jun 17 '13 at 12:38
  • @EmanuelMoecklin The program compiles in Eclipse because the library is added to my Build Path. But when I try to run in in my Android VM I get a dalvikvm Could not find class X referenced in Y – Marc Went Jun 17 '13 at 13:12
  • Can you please post the stack trace – Emanuel Moecklin Jun 17 '13 at 13:43
  • @EmanuelMoecklin Here is an image of my LogCat trace: http://puu.sh/3hKeP/5fbab723b2.png – Marc Went Jun 17 '13 at 13:45
  • That's not the full stack trace. It should be something like this: java.lang.NoClassDefFoundError: com.mwent.RaspBerry.... 03-31 17:15:55.133: ERROR/AndroidRuntime(1033): at com.package.class.method(class.java:25) ... – Emanuel Moecklin Jun 17 '13 at 13:51
  • And it should be right underneath the "Could not find class X referenced from method Y" – Emanuel Moecklin Jun 17 '13 at 13:58
  • @EmanuelMoecklin here is the full one: http://puu.sh/3hLpw/4a5312e44c.png – Marc Went Jun 17 '13 at 14:24
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/31874/discussion-between-marc-went-and-emanuel-moecklin) – Marc Went Jun 17 '13 at 14:27

1 Answers1

2

The project used JDK 1.7 while JDK 1.6 is the officially supported JDK: http://developer.android.com/sdk/index.html (see system requirements). While some developers use JDK 1.7 without problems, this case proves that doing so does come with certain risks.

Emanuel Moecklin
  • 28,488
  • 11
  • 69
  • 85
  • Let me add that using JDK 1.7 with compliance level 1.6 isn't the same as using JDK 1.6 with the same compliance level (it should but this case proves that there is indeed a difference). – Emanuel Moecklin Nov 05 '13 at 01:15