katzer / cordova-plugin-local-notifications

Cordova Local-Notification Plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can no longer compile in Cordova 5.0.0 on Android

cvoisey opened this issue · comments

Is anyone else experiencing this issue? I saw some previous posts that mentioned that the location of the files in Android have moved, however this appears to be a problem with Cordova 5.0.0.

Here is my specific error:
myDir/platforms/android/src/de/appplant/cordova/plugin/localnotification/LocalNotification.java:495: error: cannot find symbol
webView.evaluateJavascript(js, null);
^
symbol: method evaluateJavascript(String,)
location: variable webView of type CordovaWebView
myDir/platforms/android/src/de/appplant/cordova/plugin/localnotification/LocalNotification.java:492: error: cannot find symbol
webView.post(new Runnable(){
^
symbol: method post()
location: variable webView of type CordovaWebView
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: myDir/platforms/android/src/org/apache/cordova/file/ContentFilesystem.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors
:compileDebugJava FAILED

I also experience this error.

It seems that the methods post(...) and evaluateJavascript(...) are removed from the Cordova 5.0.0 CordovaWebView, and that Katzer's local notification plugin hasn't been updated to reflect these changes.

Quick fix is to modify the block starting at LocalNotification:492 with the following:

webView.getView().post(new Runnable(){
  public void run(){
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      webView.sendJavascript(js);
    } else {
      webView.loadUrl("javascript:" + js);
    }
  }
});

+1 for a fix please

The above changed recommended by nlinksteinar worked for me! I modified this and then re-added the Android plugin to my project and it compiled.

NOTE: I am not comfortable modifying the code within this project to make the change permanently for others. Perhaps someone could do that??

hi, all
I also reproduce this issue, and find this fix is still under review, can anyone help merged it? Would be very appreciate!

i tried to compile my code with and without crosswalk plugin with no success, i have cordova 5.0.0 and android 4.0.0, y apply the solution proposed by nlinksteinar and i can compile with no problem :D, i modified the code inside the plugin on android project, not on the root (cordova project) c:

I too am experiencing the webView.evaluateJavascript issue on cordova 5.0, and the fix helps.

webView.getView().post(new Runnable(){
public void run(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
webView.sendJavascript(js);
} else {
webView.loadUrl("javascript:" + js);
}
}
});

This fix by nlinksteinar helped.

+1 @nlinksteinar

+1 @nlinksteinar 's snippet

+1 for nlinksteinar... that solve the problem!!! My best...!

Error with Cordova 5

@katzer could you please add the @nlinksteinar 's snippet?
Because at the moment I always have to manually edit LocalNotification.java files.
Thanks

+1 @nlinksteinar 's snippet .
Thank you, nlinksteinar! you save my life brother...
Have good day!

Hi the @nlinksteinar's manual patch work in this way:

When we try to build Android Cordova App, some errors will marked.
Must search the files with the error, search the code line with the error and replace with @nlinksteinar code:

webView.getView().post(new Runnable(){
public void run(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
webView.sendJavascript(js);
} else {
webView.loadUrl("javascript:" + js);
}
}
});

This fix 4 apps that I am creating.
TY again to @nlinksteinar for share it.

My Best!

+1 for nlinksteinar

+1 for nlinksteinar, and be sure that your editing the right file.

If you look at the latest commit, @nlinksteinar 's suggestions have been merged into master. This should be closed.

In 8.1 continue the error, we fixed with @nlinksteinar 's suggestions. Please add in the next release.

    webView.post(new Runnable(){
           ^

symbol: method post()
location: variable webView of type CordovaWebView
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors
:compileDebugJava FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':compileDebugJava'.

    Compilation failed; see the compiler error output for details.

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

BUILD FAILED

commented

Thanks @nlinksteinar. Using webView.loadUrl("javascript:" + myCode); and it works.

I'm sorry I'm a bit lost here. I understand that the evaluateJavascript method has been removed and therefore the need to fall back to sendJavascript. But then why are you keeping the Build.VERSION check? It is no longer needed!

This is still failing for me on Cordova 6. Is there reliable fork I can use with the fix? Or shall I create my own?

Thanks!!

@sdurandeu Now there is a new upgrade for this plugin. Use the next one: https://www.npmjs.com/package/phonegap-plugin-push

@cagb80 Thanks! My understanding was that phonegap-plugin-push could only receive external notifications. Is it possible to send local notifications with it?

Just in case it helps anyone reading, my issue was that the version in NPM of the plugin is quite outdated. Installing it from this repo worked as expected.

I want Local Notification when app is closed 0r killed but i am getting some problem with webView Can you Please any one help on this ???