问题
I have a project that references two library projects. After upgrading the ADT and SDK tools to version 17, the app crashes as soon as it hits a reference to a class defined in one of the Library projects. Errors such as:
Unable to resolve superclass of Lcom/my/package/name/MyActivity; (118)
Link of class 'Lcom/my/package/name/MyActivity;' failed
VFY: unable to find class referenced in signature (Lcom/my/package/name/MyActivity;)
and:
FATAL EXCEPTION: main
java.lang.VerifyError: my/package/name/util/SomeClass
at my.package.name.App.onCreate(App.java:120)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:969)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3925)
at android.app.ActivityThread.access$1300(ActivityThread.java:122)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1184)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4340)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
(My package and classes are aren't named that way, just modified them for posting here)
Any ideas on what is happening here? As far as I can tell there are no build errors and my project looks like it is referencing the library project correctly.
回答1:
I had the exact same problem. Finding this post: How to fix the “NoClassDefFoundError” with ADT 17 save me some frustration.
回答2:
Whew, that was scary but I just tried a ton of different things until it worked. Somewhere within all of this, it resolved it. My library project has a handful of jars added to the "lib" folder and attached to the build path.
I read this change log note: http://tools.android.com/recent/dealingwithdependenciesinandroidprojects about changes to libraries and dependencies. I noticed this:
Projects have source folders, as well as Library Project and jar file dependencies. With no other setup needed than adding Library Projects as a dependency in project.properties, a project’s classpath is automatically populated with:
The content of the project’s libs/*.jar
The output of the Library Projects.
The Library Projects’ libs/*.jar
For some reason, my library project's folder was named "lib" not "libs". I have been using it that way for nearly two years without any problems, but I went ahead and changed it to "libs". I then refreshed the project, and turned the "is Library" flag off, and then on again to make sure it saw that change.
Also, with the new tools, they mention that it handles including the library project's jars in the project that references the library. Up to this point I had added the library project's jars to the referencing project manually. So I went into the referencing project, and removed the jars from the build path. I then when into the project properties and removed the library project and re-added it.
Lastly, I noticed a jar file was in the library project's folder, but wasn't being used. It was just in the folder. I removed that file.
So somewhere in there it started working again. I imagine the real fix was changing "lib" to "libs" but I wanted to make sure I mentioned it all in case it helps any other developers experiencing fear and panic in their hearts. Good luck!
回答3:
@kargi
As a rule, I think the solution here and here is a very bad practice. Maven solved this preposterous lib folder business long time ago, but Maven is also not very efficient building Android, so I would recommend using Eclipse export feature, as I describe here.
来源:https://stackoverflow.com/questions/9817372/updated-sdk-tools-and-adt-to-17-and-now-getting-verifyerrors