gpt4 book ai didi

java - GCMRegistrar jar 在 eclipse 中导致错误,未找到源。档位调试

转载 作者:行者123 更新时间:2023-12-02 00:11:45 25 4
gpt4 key购买 nike

我正在尝试使用 google GCM 注册 Android 应用程序,但它似乎在 eclipse 中导致错误。有什么帮助吗?

当我尝试检查它是否已注册时,它就爆炸了。它编译得很好,我添加了 import com.google.android.gcm.GCMRegistrar; 我认为这更多是因为我不了解 java 和 eclipse,而不是 GCM,但谁知道呢

我添加了步骤过滤器来忽略 com.google.android.gcm.*

并且我已确保将 gdm.jar 库包含在我的本地 libs 文件夹中以及我的项目和构建路径中。

如果我单步执行代码,当我尝试跨过引用 GCMRegistrar 的第一行时,它会停止,并显示“未找到源”。如果我没有设置断点,当它遇到 GCMRegistrar 并显示“未找到源”时,它仍然会停止。

private void checkRegistration(){
try{
if (!GCMRegistrar.isRegistered(getApplicationContext())) {
// Automatically registers application on startup.
GCMRegistrar.register(getApplicationContext(), Utilities.GCM_SENDER_ID);
} else {
final String regId = GCMRegistrar.getRegistrationId(getApplicationContext());
if(regId.equals("")){
GCMRegistrar.register(getApplicationContext(), Utilities.GCM_SENDER_ID);
}else{
// Device is already registered on GCM

if(regId == Utilities.getGcmRegKey(this)){

}else{
pwClient.updateGCMRef("add", regId, Utilities.getApiKey(this), Utilities.getDeviceId(this));
Utilities.setGcmRegKey(this, regId);
}
}
}
}catch(Exception ex){
Log.e("PW", "register error: " + ex.getMessage());
}
}
}

最佳答案

我不得不停止我的 GCM 项目,但我至少设法获取了 GCM 客户端内容的源代码,因此它可能会帮助您进行一些调试。从 R17 SDK 工具开始,Google 就让附加源代码和 javadoc 变得非常痛苦,但这是可以做到的。

在您发现 gcm.jar 的同一个“dist”目录中,还有另一个 jar gcm-src.jar - 这就是源代码。因此,在您的 libs 目录中创建一个名为 gcm.jar.properties 的新文件。

它应该包含一行,例如

src=C:\\dev\\tools\\android-sdk-windows4.1\\extras\\google\\gcm\\gcm-client\\dist\\gcm-src.jar

(编辑此内容以引用您的 SDK 安装,如果您使用的是 Linux,请将\\s 更改为/s)

现在关闭你的项目并重新打开它,否则它将无法工作,天知道为什么!

您现在应该有“悬停在”javadoc 类型弹出窗口上,并且能够单步执行 GCMRegistrar 静态方法。至于为什么你的代码会崩溃,也许这会让你更接近。

顺便说一句,我的项目所基于的示例代码在注册开始时有这两行

// Check that the device supports GCM (should be in a try / catch)
GCMRegistrar.checkDevice(this);
// Check the manifest to be sure this app has all the required permissions.
GCMRegistrar.checkManifest(this);

他们可能会阐明一些事情

关于java - GCMRegistrar jar 在 eclipse 中导致错误,未找到源。档位调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12666694/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com