PushPlugin register goes to errorhandler showing 'Class not found' with cordova 4.0.0 for android platform

1.7k views Asked by At

I'm building a hybrid app using Cordova (version 4.0.0) for Android.

I have added PushPlugin (https://github.com/phonegap-build/PushPlugin) to the project. While registering it goes to errorhandler and displays 'Class not found'.

I have tried various suggestion like

  • Added plugin reference in xml. Actually plugin reference is already there in config.xml file.
  • Directly install plugin using CLI (tried cordova plugin add https://github.com/phonegap-build/PushPlugin.git as well as cordova plugin add com.phonegap.plugins.pushplugin)
  • Create a new project etc.
  • PushNotification.js is added in html (<script type="text/javascript" src="js/PushNotification.js"></script>) and is located in www/js/

But still I'm getting the same message 'Class not found'

I have installed supporting plugins like device, file, media that are used by PushPlugin

Please advice if anyone has a solution for this issue.

Code sample:

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

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

There are 1 answers

2
Lepanto On BEST ANSWER

Finally got this working by adding google play service library to my project

Steps to follow:

  • Copy google-play-services_lib folder from ANDROID SDK /extras/google/google_play_services/libproject/ to your projects myproject/platform/android folder
  • Copy build.xml, local.properties & project.properties files from your myproject/platforms/android/CordovaLib folder to myproject/platforms/android/google-play-services_lib folder
  • Open project.properties file in myproject/platforms/android/google-play-services_lib folder
  • Check if project target android 19 i.e. target=android-19, if not change it to target=android-19
  • Open the project.properties from myproject/platform/android folder and add reference 2 like Following, target=android-19 android.library.reference.1=CordovaLib android.library.reference.2=google-play-services_lib

  • In CLI, goto the google-play-services_lib folder in your project and run

    android update project -p .

  • Followed by, ant debug ant release

  • If you get any error then first run ant clean debug then again run ant debug ant release

  • In CLI, goto myproject/ and build the project using cordova build android

Got this information from another post, thought this would be helpful for others who have similar issue.