4

我正在使用适用于 Android 的 Cordova(版本 4.0.0)构建一个混合应用程序。

我已将 PushPlugin ( https://github.com/phonegap-build/PushPlugin ) 添加到项目中。注册时,它会转到错误处理程序并显示“找不到类”。

我尝试了各种建议,例如

  • 在 xml 中添加了插件引用。实际上插件参考已经存在于 config.xml 文件中。
  • 使用CLI直接安装插件(试过cordova插件添加 https://github.com/phonegap-build/PushPlugin.git以及cordova插件添加com.phonegap.plugins.pushplugin)
  • 创建一个新项目等。
  • PushNotification.js 在 html( <script type="text/javascript" src="js/PushNotification.js"></script>) 中添加,位于www/js/

但我仍然收到相同的消息“找不到类”

我已经安装了支持插件,例如 PushPlugin 使用的设备、文件、媒体

如果有人对此问题有解决方案,请提出建议。

代码示例:

document.addEventListener("deviceready", onDeviceReady, false);

var pushNotification;
function onDeviceReady() {
    //Push notification
    pushNotification = window.plugins.pushNotification;
    pushNotification.register(successHandler, errorHandler, {"senderID":"xxxxxxxxxx", "ecb":"onNotification"});
}
4

1 回答 1

2

最后通过将google play 服务库添加到我的项目中来完成这项工作

要遵循的步骤:

  • 将 google-play-services_lib 文件夹复制ANDROID SDK /extras/google/google_play_services/libproject/到您的项目 myproject/platform/android文件夹
  • build.xmllocal.propertiesproject.properties文件从您的myproject/platforms/android/CordovaLib文件夹复制到myproject/platforms/android/google-play-services_lib文件夹
  • 在文件夹中打开 project.properties文件myproject/platforms/android/google-play-services_lib
  • 检查项目目标是否为 android 19 即 target=android-19,如果没有则更改为 target=android-19
  • 从文件夹中打开project.propertiesmyproject/platform/android并添加参考 2,如下所示, target=android-19 android.library.reference.1=CordovaLib android.library.reference.2=google-play-services_lib

  • 在 CLI 中,转到项目中的 google-play-services_lib 文件夹并运行

    android update project -p .

  • 其次是, ant debug ant release

  • 如果您收到任何错误,请先运行ant clean debug然后再次运行 ant debug ant release

  • 在 CLI 中,转到myproject/并使用构建项目cordova build android

从另一篇文章中获得此信息认为这对其他有类似问题的人会有所帮助。

于 2015-01-06T15:14:35.223 回答