katzer / cordova-plugin-background-mode

Keep app running in background
Apache License 2.0
1.38k stars 1.02k forks source link

Incompatiblity with older android versions #425

Open BuddyLReno opened 5 years ago

BuddyLReno commented 5 years ago

It looks like since this commit here (6b522e9832ba2dcd40b3820d9900db07a29b8aa0), some specific java features that are only enabled in android 7 and 8 were added (like Lambdas). This breaks the plugin on apps that still support android 6.

Would it be possible to amend the lambdas and other android 7 and 8 specific features to keep compatibility with android 6?

Here's an example of some of the build errors:

 /Users/buddy.reno/webapps/tdrs-app/tdrs-ionic-app/platforms/android/src/de/appplant/cordova/plugin/background/BackgroundMode.java:96: error: strings in switch are not supported in -source 1.6
[cordova]          switch (action)
[cordova]                 ^
[cordova]    (use -source 7 or higher to enable strings in switch)
[cordova]  /Users/buddy.reno/webapps/tdrs-app/tdrs-ionic-app/platforms/android/src/de/appplant/cordova/plugin/background/BackgroundModeExt.java:260: error: method references are not supported in -source 1.6
[cordova]                  activity.runOnUiThread(dialog::show);
[cordova]                                                 ^
[cordova]    (use -source 8 or higher to enable method references)
[cordova]  /Users/buddy.reno/webapps/tdrs-app/tdrs-ionic-app/platforms/android/src/de/appplant/cordova/plugin/background/BackgroundModeExt.java:242: error: lambda expressions are not supported in -source 1.6
[cordova]                  dialog.setPositiveButton(ok, (o, d) -> activity.startActivity(intent));
[cordova]                                                      ^
[cordova]    (use -source 8 or higher to enable lambda expressions)
[cordova]  /Users/buddy.reno/webapps/tdrs-app/tdrs-ionic-app/platforms/android/src/de/appplant/cordova/plugin/background/BackgroundMode.java:295: error: lambda expressionsare not supported in -source 1.6
[cordova]          cordova.getActivity().runOnUiThread(() -> webView.loadUrl("javascript:" + js));
[cordova]                                                 ^
[cordova]    (use -source 8 or higher to enable lambda expressions)
BuddyLReno commented 5 years ago

Ok it looks like I just need to set source and target compatibility versions to 1.8 in Android Studio 👍 I'll leave this open for now in case other people stumble across this issue.

debugger200 commented 5 years ago

Still i'm facing the same issue in Cordova-Android 6.4.0. The automated builds won't work with the above fix. is there any thing we can do now? if we don't use the URL (https://github.com/katzer/cordova-plugin-background-mode.git) to install this plugin then the plugin works fine in Android but iOS build is crashed when open the app, might be due to a key change done in this plugin a year ago.

Now using this URL the plugin works fine in iOS but android build is not passing. Please let us know if we can make some workaround to both platform with a fix?

phyr0s commented 5 years ago

Same error here with cordova-android 7.1.4

debugger200 commented 5 years ago

At least this iOS Crash fix should be merged to repo located at npmjs.

boedy commented 5 years ago

Feel free to fork my fork. Adds support for older Cordova versions.

mehmetkaynak commented 5 years ago

Feel free to fork my fork. Adds support for older Cordova versions.

How do I install this to visual studio 2017?

image

casper123 commented 5 years ago

@boedy i tried your fork on android6.4 but it's not working. Same error

boedy commented 5 years ago

@mehmetkaynak @casper123

This works for me when trying it on a new empty project:

cordova create background-mode-test
cd background-mode-test
cordova platform add android@6.3.0
cordova plugin add https://github.com/boedy/cordova-plugin-background-mode/
cordova build android

I'm still on Cordova version 6.5.0. Not sure if that impacts anything.

jetma commented 4 years ago

I solved the problem by reinstalling this plugin:

cordova plugin rm cordova-plugin-background-mode
cordova plugin add cordova-plugin-background-mode
mirko77 commented 4 years ago

I have the same issue with Cordova 6.5.0


:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
/Users/mirko/Sites/epicollect5-mobile-app-legacy/platforms/android/src/de/appplant/cordova/plugin/background/BackgroundModeExt.java:168: error: lambda expressions are not supported in -source 1.6
                    getApp().runOnUiThread(() -> {
                                              ^
  (use -source 8 or higher to enable lambda expressions)
/Users/mirko/Sites/epicollect5-mobile-app-legacy/platforms/android/src/de/appplant/cordova/plugin/background/BackgroundModeExt.java:257: error: method references are not supported in -source 1.6
                activity.runOnUiThread(dialog::show);
                                               ^
  (use -source 8 or higher to enable method references)
/Users/mirko/Sites/epicollect5-mobile-app-legacy/platforms/android/src/de/appplant/cordova/plugin/background/BackgroundMode.java:295: error: lambda expressions are not supported in -source 1.6
        cordova.getActivity().runOnUiThread(() -> webView.loadUrl("javascript:" + js));
                                               ^
  (use -source 8 or higher to enable lambda expressions)
3 errors
:compileDebugJavaWithJavac FAILED
mirko77 commented 4 years ago

@mehmetkaynak @casper123

This works for me when trying it on a new empty project:

cordova create background-mode-test
cd background-mode-test
cordova platform add android@6.3.0
cordova plugin add https://github.com/boedy/cordova-plugin-background-mode/
cordova build android

I'm still on Cordova version 6.5.0. Not sure if that impacts anything.

I get this error with your fork when compiling with API 28:


error: cannot find symbol
import android.app.NotificationChannel;
                  ^
  symbol:   class NotificationChannel
  location: package android.app
/Users/mirko/Sites/epicollect5-mobile-app-legacy/platforms/android/src/de/appplant/cordova/plugin/background/ForegroundService.java:184: error: cannot find symbol
        NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name,importance);
        ^
  symbol:   class NotificationChannel
  location: class ForegroundService
/Users/mirko/Sites/epicollect5-mobile-app-legacy/platforms/android/src/de/appplant/cordova/plugin/background/ForegroundService.java:184: error: cannot find symbol
        NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name,importance);
                                           ^
  symbol:   class NotificationChannel
  location: class ForegroundService
/Users/mirko/Sites/epicollect5-mobile-app-legacy/platforms/android/src/de/appplant/cordova/plugin/background/ForegroundService.java:207: error: cannot find symbol
                   notification.setChannelId(CHANNEL_ID);
                               ^
  symbol:   method setChannelId(String)
  location: variable notification of type Builder
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.
4 errors