开发者

classdefnotfound error in eclipse (strange)

I am getting a classdefnotfound error at runtime for my Android app. Everything runs fine except this one class. Previously this class worked. The class is actually in an external library and all libraries are correct. Has anyone run across any thing like this in eclipse? I feel like it is an environment problem.

The class is in google api client library version 1.4.1.

classdefnotfound: com.google.api.client.xml.XmlNamespaceDictionary;

The开发者_运维知识库 jar file is in the lib directory and in the .classpath file.


if this class is an activity, then make sure you add it to your AndroidManifest.xml file!


I encountered this problem quite unexpectedly, and couldn't really fix it with proposed solutions. As it turned out, this blog post was very helpful. In short, I had all my libraries in lib folder instead of libs, and added them to Eclipse's build path. But in the latter case, Android automatically adds your libraries. Renaming the folder to libs and removing previous manual changes to the classpath fixed the problem.


From what I've noticed this error is usually caused by a ClassNotFoundException and in my case this exception was thrown because I had implemented interfaces which were not yet introduced during the time of release of the version of the android OS on which the app was running...this apparently caused the class to not be recognized at runtime.


Sometimes this happens when you export your project and use obfuscation. Proguard will erase classes that are only mentionned in the manifest.xml and not used directly in your code (such as introspection class loading).

In that case, you should configure proguard to keep your class, look at proguard.cfg and add a line for your class.

Also, if this happens in debug mode and not for an exported app, then you could unzip your apk file, use dexdump to see if your class is included in your dex file or not.

dexdump comes with the android sdk and can be used to decompile classes.dex in your apk.

Regards,
Stéphane


Ok, I've figured it out(after 8 hours of hair pulling!). The google client lib jar files were located in another project(the one that was working). I had added them to the project as a referenced library. For some reason it was not getting added at compile time. Solution: copied the actual jar files to the /lib directory and update the build path in eclipse by removing the referenced libs

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜