问题
I have the gcm.jar in my classpath, so eclipse compiles the project but it fails on my Nexus 4 device with
02-24 11:52:12.645: E/AndroidRuntime(30240): FATAL EXCEPTION: main
02-24 11:52:12.645: E/AndroidRuntime(30240): java.lang.NoClassDefFoundError: com.google.android.gcm.GCMRegistrar
02-24 11:52:12.645: E/AndroidRuntime(30240): at com.foo.closethedoor.CloseTheDoorActivity.onCreate(CloseTheDoorActivity.java:77)
回答1:
I have the gcm.jar in my classpath
It needs to be in your project's libs/
directory. Do not just manipulate the Eclipse build path manually -- that will allow you compile against the JAR but does not ship the JAR with your APK. Putting the JAR in libs/
does both.
回答2:
NoClassDefFoundError means the Application is unable to find the location of the file inside the Application's folder. It is advised to keep all the library files and jar files in 'libs' folder of the Project.Try doing so.It will resolve the issue. If not, try building the code again before pushing it onto the device.
来源:https://stackoverflow.com/questions/15055351/getting-noclassdeffounderror-with-google-cloud-messaging-gcm-on-nexus-4