GCM:java.lang.noclassdeffounderror:com.google.android.gcm.GCMRegistrar
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11273938/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
GCM : java.lang.noclassdeffounderror: com.google.android.gcm.GCMRegistrar
提问by user1492955
I am trying to register a device onto GCM using the following code:
我正在尝试使用以下代码将设备注册到 GCM:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GCMRegistrar.checkDevice(this);
// the following function can be removed when deploying the app
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
GCMRegistrar.register(this, SENDER_ID);
} else {
Log.v(TAG, "Already registered");
}
I have imported import com.google.android.gcm.GCMRegistrar;
and also added GCM.jar to my buildpath in Eclipse which i got thru the sdk download
我已经导入了 import com.google.android.gcm.GCMRegistrar;
并将 GCM.jar 添加到我在 Eclipse 中的构建路径中,这是我通过 sdk 下载获得的
Please help !
请帮忙 !
回答by Lalit Poptani
In the updated ADT(Above ADT 17) you have to put jar files inside libs
folder and not lib
. So make sure that you put gcm.jar
file inside libs
and not lib
folder.
在更新的 ADT(ADT 17 以上)中,您必须将 jar 文件放在libs
文件夹中,而不是lib
. 因此,请确保将gcm.jar
文件放入libs
而不是lib
文件夹中。
回答by user1503987
Just go to project properties -> java build path -> "order and export " now giv a tick on the jar file "GCM.jar" that you have added
只需转到项目属性 -> java 构建路径 ->“订购和导出”现在在您添加的 jar 文件“GCM.jar”上打勾
回答by Hymansonkr
My gcm.jar
was already in libs, so it wasn't a folder naming issue for me..
我gcm.jar
已经在库中了,所以这对我来说不是文件夹命名问题..
I had to go to Right Click
> Build Path
> Configure Build path...
for the project in question and I removed the following:
我不得不去Right Click
> Build Path
>Configure Build path...
有问题的项目,我删除了以下内容:
- Any lingering files outside of a folder/bundle
Android Private Libraries
- Any bundles with the word 'reference' in them (you may not have one)
- 文件夹/捆绑包之外的任何遗留文件
Android Private Libraries
- 任何包含“参考”一词的捆绑包(您可能没有)
You might get a lot of "errors" in your project so restart Eclipse and let it clean. Once it cleans you'll have no errors. Run your project and viola.
您的项目中可能会出现很多“错误”,因此请重新启动 Eclipse 并使其清理干净。一旦它清理你就没有错误。运行您的项目和中提琴。
Thanks to DLewfor this answer.
感谢DLew的回答。
回答by Shamitha
Make a folder libsin your project folder and put the gcm.jar in it. Then add it to your class path using add external jarsin configure build pathoption.
在您的项目文件夹中创建一个文件夹libs并将 gcm.jar 放入其中。然后使用在配置构建路径选项中添加外部 jar将其添加到您的类路径中。
回答by Carlos ALVAREZ
You have to put gcm.jar file inside libs, then go to project Properties > Java Build Path > Librariesand add it to your path using Add External JARs..., after in Order and Exportyou check gcm.jar and press OK. That should work
您必须将 gcm.jar 文件放在libs 中,然后转到项目Properties > Java Build Path > Libraries并使用Add External JARs...将其添加到您的路径中,然后在Order 和 Export 中检查 gcm.jar 并按OK。那应该工作
回答by busylee
I had same problem, after update SDK in my project. it helped for me: I just "add support library" in "Android tools". Hope this helps anyone else.
在我的项目中更新 SDK 后,我遇到了同样的问题。它对我有帮助:我只是在“Android 工具”中“添加支持库”。希望这对其他人有帮助。
回答by Madhu
Me also got same problem, after adding android-support-v4.jar
and gcm.jar
into my libs folder no issues found its work like a charm
我也遇到了同样的问题,在添加android-support-v4.jar
并gcm.jar
进入我的 libs 文件夹后,没有发现它的工作就像一个魅力
Thanks
谢谢
回答by Klaasvaak
Make sure that the gcm jar file is in the right libs folder and added into the java build path at your project properties.
确保 gcm jar 文件位于正确的 libs 文件夹中并添加到项目属性的 java 构建路径中。
回答by matt.hallman
The SENDER_ID field should be the project ID from when you created your google api project. Read the beginning of this: http://developer.android.com/guide/google/gcm/gs.html#libs
SENDER_ID 字段应该是您创建 google api 项目时的项目 ID。阅读本文开头:http: //developer.android.com/guide/google/gcm/gs.html#libs
TAG should also be a string -> ""tag Name"
TAG 也应该是一个字符串 -> ""tag Name"
回答by Jotiram Chavan
Hello You are using old GCM implementations use new implementations available on https://developers.google.com/cloud-messaging/android/start
您好您正在使用旧的 GCM 实现使用https://developers.google.com/cloud-messaging/android/start 上提供的新实现