I am working on the push notification integration of my Flutter application and have been facing the following issue with the Android build of the app regarding a “PendingIntent” requiring a “FLAG_IMMUTABLE” argument.
Since template-based pushing currently fails, is there a method through the Backendless console of sending push notifications that are not template based?
Backendless Version (3.x / 5.x, Online / Managed / Pro )
Please describe the expected behavior of the issue, starting from the first action.
Send a push notification template from the Backendless Console
Push notification is handled while mobile app is backgrounded
Actual Behavior
Send a push notification template from the Backendless Console
Push notification handler crashes with the following:
E/BackendlessFCMService( 3090): Error processing push notification
E/BackendlessFCMService( 3090): java.lang.IllegalArgumentException: us.boundlessdesign.customer_support_blue: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
E/BackendlessFCMService( 3090): Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
E/BackendlessFCMService( 3090): at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
E/BackendlessFCMService( 3090): at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:458)
E/BackendlessFCMService( 3090): at android.app.PendingIntent.getActivity(PendingIntent.java:444)
E/BackendlessFCMService( 3090): at android.app.PendingIntent.getActivity(PendingIntent.java:408)
E/BackendlessFCMService( 3090): at com.backendless.push.PushTemplateHelper.convertFromTemplate(PushTemplateHelper.java:267)
E/BackendlessFCMService( 3090): at com.backendless.push.BackendlessFCMService.handleMessageWithTemplate(BackendlessFCMService.java:134)
E/BackendlessFCMService( 3090): at com.backendless.push.BackendlessFCMService.handleMessage(BackendlessFCMService.java:102)
E/BackendlessFCMService( 3090): at com.backendless.push.BackendlessFCMService.onMessageReceived(BackendlessFCMService.java:68)
E/BackendlessFCMService( 3090): at com.google.firebase.messaging.FirebaseMessagingService.dispatchMessage(FirebaseMessagingService.java:235)
E/BackendlessFCMService( 3090): at com.google.firebase.messaging.FirebaseMessagingService.passMessageIntentToSdk(FirebaseMessagingService.java:185)
E/BackendlessFCMService( 3090): at com.google.firebase.messaging.FirebaseMessagingService.handleMessageIntent(FirebaseMessagingService.java:172)
E/BackendlessFCMService( 3090): at com.google.firebase.messaging.FirebaseMessagingService.handleIntent(FirebaseMessagingService.java:161)
E/BackendlessFCMService( 3090): at com.google.firebase.messaging.EnhancedIntentService.lambda$processIntent$0$EnhancedIntentService(EnhancedIntentService.java:78)
E/BackendlessFCMService( 3090): at com.google.firebase.messaging.-$$Lambda$EnhancedIntentService$NSk2h75eWhBOI4TsAFgvvtv1g9o.run(Unknown Source:6)
In trying to upgrade to the latest Flutter Backendless SDK in order to get the fix for the notification issue, I’m getting the following new error with Android gradle compilation:
C:\Users\xxx\AppData\Local\Pub\Cache\hosted\pub.dev\backendless_sdk-7.3.3\android\src\main\java\com\backendless\backendless_sdk\call_handlers\RtCallHandler.java:172: error: lambda expressions are not supported in -source 7
new Handler(Looper.getMainLooper()).post(() -> methodChannel.invokeMethod("Backendless.RT." + method + ".EventResponse", arguments));
^
(use -source 8 or higher to enable lambda expressions)
1 error
I’m upgrading from version 7.2.7 and the lambda expression that’s a part of that referenced line is new since 7.2.7.
In my app/build.gradle I specify the following in order to support java. 8 features as recommended in the Android documentation, but it doesn’t appear to be “working” and I’m struggling to find a solution:
This issue appears when your Java is older version that project requires.
You need to make sure that your project is actually using the correct version of Java. You indicated in the gradle that the project will use version 8, but your build may still be using the older one. Try updating dependencies and cleaning up the project.
Output from “flutter doctor -v” indicates that my Java version being used is 11, which is greater than 8. I believe that should be fine?
• Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
I have updated everything that I know to update (latest version of flutter and all dependencies) and I have multiple times done a “flutter clean” and re-get of packages.
I’m not super confident, but this looks fine to me. I had no issue with compilation of Backendless SDK versions up to 7.2.7.
$ ./gradlew --version
------------------------------------------------------------
Gradle 6.7
------------------------------------------------------------
Build time: 2020-10-14 16:13:12 UTC
Revision: 312ba9e0f4f8a02d01854d1ed743b79ed996dfd3
Kotlin: 1.3.72
Groovy: 2.5.12
Ant: Apache Ant(TM) version 1.10.8 compiled on May 10 2020
JVM: 15.0.2 (Oracle Corporation 15.0.2+7-27)
OS: Linux 4.4.0-19041-Microsoft amd64
I have now tried to build my application and have gotten the same error about the lambda expression on my initial Windows machine and two additional MacOS machines, one of which had a clean install of everything.
Alright I was finally able to get compilation working again by moving to the latest Flutter-supported Gradle version and altering my gradle configurations until a build succeeded.
Thank you for the assistance and for the fixing of the original notification problem!