views:

265

answers:

1

I'm seeing this question is getting asked a lot in many different contexts. Perhaps we can set some strategies for locating and fixing it? I'm noobish myself so all I can contribute are horror stories and questions, sorry...

It seems this is thrown when a class is visible at compile time but not at run time... how can this happen?

In my case I am developing an app that uses the Google APIs, in Eclipse, for the Android platform. I've configured the Project Properties / Java Build Path / Libraries to include the gdata .jars and all is well. When I execute in the emulator I get a force close and the logcat shows a NoClassDefFoundError on a simple new ContactsService("myApp"); I've also tried a new CalendarService("myApp") with the same results.

Is it possible or desirable to statically bind at compile time to avoid the problem?

How could dynamic binding of an add-on library work in the mobile environment anyway? Either it has to be bound into my .apk or else I need to "install" it? ... hmmm.

Advice much appreciated.

+1  A: 

It seems this is thrown when a class is visible at compile time but not at run time... how can this happen?

The build classpath may include JARs that are not being packaged into the APK.

Is it possible or desirable to statically bind at compile time to avoid the problem?

It is possible, desirable, and necessary.

Outside of Eclipse, you just put the JARs you need in libs/ in your project, compile with Ant, and you are done.

Inside of Eclipse, one pattern I have had students use with success is to put the JARs you need in libs/ in your project, add them as JARs to the build path (note: not external JARs), and they get packaged as part of the APK. Note, though, that I do not personally use Eclipse, and so my experience with it is limited.

CommonsWare
With the Eclipse plugin for Android development any jars included in the project's build path are packaged as part of the APK (as long as you are using the plugin to build the APK). The jars do not have to be within the project, or in a certain directory or anything.
mbaird
There's been a rash of complaints recently about this, though. Again, I'm not an Eclipse user. I've seen that there is "Add JAR" and "Add External JAR" on the one build path dialog tab -- is there maybe some impact if you choose "Add External JAR"?
CommonsWare
I have been using "Add External JAR", yes. I created a libs directory and moved the gdata installs directly into it. Then I used "Add JAR" and the jars show up as "Referenced Libraries" and the compiler is happy. Then I did a Project Clean, restarted Eclipse and the emulator, and ran. Same problem. Grrr. This thing is kickin me .. :) Looks like a dev environment bug?
DJC
Found on code.google.com gdata-java-client thread:vbarathan 2/10/09This client library is not intended for mobile platforms primarily for the memory footprint related to parsing large xml responses... there may be other opensource efforts in the near future to come with a mobile compatible library.Similar comments add evidence that the Google API's other than maps are not available at all on Android. That said, a 2.0 beta was posted 4 days ago with this comment: "Much better experience on Android: much smaller library, and much more efficient" ...
DJC
Following up... Rewritten from scratch, the version 2 client library is an independent incompatible client library from version 1. Version 2 supports most (but not yet all) major features of version 1, plus:Support for Android (minimum 1.5 SDK), featuring a much smaller library...
DJC