Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Uncaught ReferenceError: PushNotification is not defined #271

Closed
sulthanallaudeen opened this issue Oct 28, 2015 · 36 comments
Closed

Uncaught ReferenceError: PushNotification is not defined #271

sulthanallaudeen opened this issue Oct 28, 2015 · 36 comments
Labels

Comments

@sulthanallaudeen
Copy link

I am getting Uncaught ReferenceError: PushNotification is not defined whenever i run the example..

If i install this plugin

cordova plugin add phonegap-plugin-push

or

cordova plugin add https://github.com/phonegap/phonegap-plugin-push

I can't able to run the app itself

This is the line i am getting error

var push = PushNotification.init({

What is the problem and how can i fix this ?

@sulthanallaudeen
Copy link
Author

Here is the error i got in the command prompt

FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred configuring root project 'android'.

    Could not resolve all dependencies for configuration ':_debugCompile'.
    Could not find any version that matches com.android.support:support-v13:23+
    .
    Searched in the following locations:
    https://repo1.maven.org/maven2/com/android/support/support-v13/maven-me
    tadata.xml
    https://repo1.maven.org/maven2/com/android/support/support-v13/
    file:/E:/dummy/adt-bundle-windows-x86_64-20140702/sdk/extras/android/m2
    repository/com/android/support/support-v13/maven-metadata.xml
    file:/E:/dummy/adt-bundle-windows-x86_64-20140702/sdk/extras/google/m2r
    epository/com/android/support/support-v13/maven-metadata.xml
    file:/E:/dummy/adt-bundle-windows-x86_64-20140702/sdk/extras/google/m2r
    epository/com/android/support/support-v13/
    Required by:
    :android:unspecified

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug
    option to get more log output.

BUILD FAILED

Total time: 6.053 secs

C:\Users\anas\newpush\platforms\android\cordova\node_modules\q\q.js:126
throw e;
^
Error code 1 for command: cmd with args: /s /c "C:\Users\anas\newpush\platforms
android\gradlew cdvBuildDebug -b C:\Users\anas\newpush\platforms\android\build.g
radle -PcdvBuildArch=x86 -Dorg.gradle.daemon=true"
ERROR running one or more of the platforms: Error: cmd: Command failed with exit
code 1
You may not have the required environment or OS to run this project

@bmwsedee
Copy link

I encountered this on a computer of one of my colleagues just yesterday,
and it turned out not all dependencies as mentioned in the docs
https://github.com/phonegap/phonegap-plugin-push#compiling were installed.
It says to install:

  • Android Support Library version 23 or greater
  • Android Support Repository version 20 or greater
  • Google Play Services version 27 or greater
  • Google Repository version 22 or greater

On Wed, Oct 28, 2015 at 12:52 PM Sulthan Allaudeen notifications@github.com
wrote:

Here is the error i got in the command prompt

FAILURE: Build failed with an exception.

What went wrong:
A problem occurred configuring root project 'android'.

Could not resolve all dependencies for configuration ':_debugCompile'.
Could not find any version that matches
com.android.support:support-v13:23+
.
Searched in the following locations:
https://repo1.maven.org/maven2/com/android/support/support-v13/maven-me
tadata.xml
https://repo1.maven.org/maven2/com/android/support/support-v13/
file:/E:/dummy/adt-bundle-windows-x86_64-20140702/sdk/extras/android/m2
repository/com/android/support/support-v13/maven-metadata.xml
file:/E:/dummy/adt-bundle-windows-x86_64-20140702/sdk/extras/google/m2r
epository/com/android/support/support-v13/maven-metadata.xml
file:/E:/dummy/adt-bundle-windows-x86_64-20140702/sdk/extras/google/m2r
epository/com/android/support/support-v13/
Required by:
:android:unspecified

Try:
Run with --stacktrace option to get the stack trace. Run with --info
or --debug
option to get more log output.

BUILD FAILED

Total time: 6.053 secs

C:\Users\anas\newpush\platforms\android\cordova\node_modules\q\q.js:126
throw e;
^
Error code 1 for command: cmd with args: /s /c
"C:\Users\anas\newpush\platforms
android\gradlew cdvBuildDebug -b
C:\Users\anas\newpush\platforms\android\build.g
radle -PcdvBuildArch=x86 -Dorg.gradle.daemon=true"
ERROR running one or more of the platforms: Error: cmd: Command failed
with exit
code 1
You may not have the required environment or OS to run this project


Reply to this email directly or view it on GitHub
#271 (comment)
.

@sulthanallaudeen
Copy link
Author

So, i want to install all these ?

  • Android Support Library version 23 or greater
    • Android Support Repository version 20 or greater
    • Google Play Services version 27 or greater
    • Google Repository version 22 or greater

@sulthanallaudeen
Copy link
Author

@bmwsedee It worked after installing all those packages ?

@macdonst
Copy link
Member

@sulthanallaudeen yes, those packages are necessary for this plugin to function properly. Once you install them and re-test please close this issue if it is resolved.

@sulthanallaudeen
Copy link
Author

@macdonst Ok thanks, i will update and re-test the mentioned packages and will do it accordingly

@ste5787
Copy link

ste5787 commented Oct 28, 2015

To solve the problem you have simpy to put the code into
$ionicPlatform.ready(function() {
var push = PushNotification.init({
});

it's right? :)

@macdonst
Copy link
Member

@ste5787 well yeah, if the user is not waiting for $ionicPlatform.ready() or the deviceready event than none of this stuff will work.

@sulthanallaudeen
Copy link
Author

@ste5787 @macdonst @bmwsedee

Thanks, I have updated the given packages in Android Studio

And i noted that the function is already inside the onDeviceReady

Still i am facing the error.. What could be the issue ?

onDeviceReady: function() {
alert('started');
var push = PushNotification.init({
"android": {
"senderID": "762187383962"
},
"ios": {"alert": "true", "badge": "true", "sound": "true"},
"windows": {}
});
....

I did the again did the fresh install of project and installed the phonegap-plugin-push by

cordova plugin add phonegap-plugin-push

Then when i try to run

I am still getting the error

Here is the Error Trace

FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred configuring root project 'android'.

    Could not resolve all dependencies for configuration ':_debugCompile'.
    Could not find any version that matches com.android.support:support-v13:23+
    .
    Searched in the following locations:
    https://repo1.maven.org/maven2/com/android/support/support-v13/maven-me
    tadata.xml
    https://repo1.maven.org/maven2/com/android/support/support-v13/
    file:/E:/dummy/adt-bundle-windows-x86_64-20140702/sdk/extras/android/m2
    repository/com/android/support/support-v13/maven-metadata.xml
    file:/E:/dummy/adt-bundle-windows-x86_64-20140702/sdk/extras/google/m2r
    epository/com/android/support/support-v13/maven-metadata.xml
    file:/E:/dummy/adt-bundle-windows-x86_64-20140702/sdk/extras/google/m2r
    epository/com/android/support/support-v13/
    Required by:
    :android:unspecified

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug
    option to get more log output.

BUILD FAILED

Total time: 6.228 secs

C:\Users\anas\newpush\platforms\android\cordova\node_modules\q\q.js:126
throw e;
^
Error code 1 for command: cmd with args: /s /c "C:\Users\anas\newpush\platforms
android\gradlew cdvBuildDebug -b C:\Users\anas\newpush\platforms\android\build.g
radle -PcdvBuildArch=arm -Dorg.gradle.daemon=true"
ERROR running one or more of the platforms: Error: cmd: Command failed with exit
code 1
You may not have the required environment or OS to run this project

What should i do now ?

@bmwsedee
Copy link

@sulthanallaudeen Just to be sure, but did you install the necessary components in the Android SDK Manager?
Also, does the project compile without the plugin, or do you also get errors when you remove it?

@sulthanallaudeen
Copy link
Author

@bmwsedee Yes i have install the necessary components in the Android SDK Manager..

If i remove the plugin and run the project.. the app is getting installed in the Device but I am getting PushNotification is not defined still (I found the error in the chrome::/inspect )

@ste5787
Copy link

ste5787 commented Oct 29, 2015

Please try this: whit inspector opened write "PushNotification" in the console and than press enter key. What happen?

@bmwsedee
Copy link

@sulthanallaudeen What version of the plugin are you using? Maybe downgrading to 1.3.0 helps (as suggested in #273) or maybe #179 gives any hints?
The error in the console is not surprise really if you remove the plugin, that was just to make sure the error only occurs when including the plugin.

@macdonst
Copy link
Member

@sulthanallaudeen you have to resolve the problem where the dependency com.android.support:support-v13:23+ cannot be resolved. Something is not setup correctly in your android environment.

Make sure your $ANDROID_HOME environment variable is set correctly.

Try opening the project in Android Studio (the platforms/android directory) to see if Android Studio can compile the project. That'll let you know if you've actually got all the dependencies downloaded.

@sulthanallaudeen
Copy link
Author

@macdonst The $A\NDROID_HOME is set correctly.

@bmwsedee @ste5787 Can you tell me whether i am doing correctly.

  1. I created a empty cordova project
  2. Downloaded the .zip of https://github.com/phonegap/phonegap-plugin-push

and navigated to example->www-> and copied the files

and pasted the www content to the project's www location

and i am trying the above steps..

Is that correct way ?

Or should i do something else ?

@sulthanallaudeen
Copy link
Author

@ste5787 Now i can't even run the cordova project due to the build error . But can you pls say me whether the steps i followed above was correct ?

@sulthanallaudeen
Copy link
Author

@bmwsedee May i know how to downgrade ? Can you tel me whether the steps i used to do is correct ? Or should i achieve in it some other steps ?

@bmwsedee
Copy link

@sulthanallaudeen Downgrading can be done by removing the existing plugin (phonegap plugin remove phonegap-plugin-push) and installing the plugin with a specific version (phonegap plugin add phonegap-plugin-push@1.3.0).

I do however think that @macdonst suggestion of opening the project in Android Studio and see if it compiles there will help you the most; your problem seems to be dependency-related.

@sulthanallaudeen
Copy link
Author

@bmwsedee Thanks, i will follow it..

Can you tel me whether the steps i am doing is correct ?

  1. I created a empty cordova project
  2. Downloaded the .zip of https://github.com/phonegap/phonegap-plugin-push
  3. and navigated to example->www-> and copied the files
  4. and pasted the www content to the project's www location
  5. Tying to built

Is that correct way ?

@bmwsedee
Copy link

@sulthanallaudeen If you want a default implementation for handling notifications you will need steps 2-4, if you just want to know whether you can install the plugin and build your project you will only need to do steps 1 and 5 (supposing step 1 includes the installation of the plugin)

@sulthanallaudeen
Copy link
Author

@bmwsedee

Yes, I tried 2, 4 .. just wanted to implement the default handling of notifications.

I tried that only .

@macdonst
Copy link
Member

@sulthanallaudeen oh no, that is not the way you install a plugin into a project. This is what you should be doing:

  1. Create an empty cordova project
  2. Add the platform you require, for example phonegap platform add android
  3. Add the plugin to your project. phonegap plugin add phonegap-plugin-push
  4. Navigate to example->www-> and copied the files
  5. Paste the www content to the project's www location
  6. Build

@sulthanallaudeen
Copy link
Author

@macdonst Thanks, i followed your instruction and now i can able to run the application and get gcm id. So, i am closing this one.

Thanks for the support guys 👍

@nadeemkhoury
Copy link

Guys, I still get the same error. although I installed the android SDK components, and follow all the above steps. but nothing has worked for me. PLEASE HELP

@sulthanallaudeen
Copy link
Author

What error you getting ?

@nadeemkhoury
Copy link

Thank you sulthan, I fixed my problem by adding this code to my config.xml:


also, I was debugging in ripple, which will now work unless you debug it on real device.

Thank you so much.

@yossale
Copy link

yossale commented Nov 16, 2015

@nadeemkhoury can you share which code you added to your config.xml? I'm still having the same problem

@nadeemkhoury
Copy link

<platform name="android">
    <preference name="android-minSdkVersion" value="15"/>
 </platform>

this code my friend.

@fredgalvao
Copy link
Collaborator

@nadeemkhoury do you have the crosswalk plugin installed on your project? The solution proposed by you doesn't make sense unless you do, as that's a pretty common crosswalk issue.

@nadeemkhoury
Copy link

hey bro @fredgalvao, No I don't have crosswalk plugin. I think the main problem was debugging using ripple, when I test it on device it works smoothly. but also the code that I had included above has a role in fixing my issue.

@yossale
Copy link

yossale commented Nov 18, 2015

@nadeemkhoury it worked, thanks!

@sekhar-ashwin
Copy link

sekhar-ashwin commented Apr 16, 2016

Make Sure that you include right cordova.js and cordova_plugins.js file.
Both the files are auto generated while phonegap build. Enjoy !!

@hungca
Copy link

hungca commented Oct 6, 2016

Remove ng-app in index.html and put this http://stackoverflow.com/questions/21556090/cordova-angularjs-device-ready.
your app controller/factory/service will run after device ready and PushNotification will be available

@chrillewoodz
Copy link

chrillewoodz commented Oct 25, 2017

I'm using Angular 2 and trying to get this to work.

    this.renderer.listen('document', 'deviceready', () => {

      const push = PushNotification.init({
        android: {
          senderID: 'mySenderID'
        },
        ios: {
  
        }
      });

      push.on('registration', (data) => {
        // data.registrationId
        console.log(data);
      });

      push.on('notification', (data) => {
        // data.message,
        // data.title,
        // data.count,
        // data.sound,
        // data.image,
        // data.additionalData
      });

      push.on('error', (e) => {
        // e.message
        console.log(e)
      });
    });

But even if I wait for deviceready it still says that it's not defined. I've installed all necessary SDK tools etc. but still can't get it to work. Please help.

@gaurav-chandra
Copy link

+1 for me in ionic 2 push plugin v 2.1.3

@lock
Copy link

lock bot commented Jun 3, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests