cordova-plugin-fcm-with-dependecy-updated icon indicating copy to clipboard operation
cordova-plugin-fcm-with-dependecy-updated copied to clipboard

Support for Android SDK 31

Open marutifh opened this issue 3 years ago • 15 comments

Hi,

When we set target SDK to 31, it gives a compile time error, so added fix for this.

Error observed

Manifest merger failed : Apps targeting Android 12 and higher are required to specify an explicit value for android:exported when the corresponding component has an intent filter defined. See https://developer.android. com/guide/topics/manifest/activity-element#exported for details.

marutifh avatar Jan 07 '22 10:01 marutifh

This pull request is really important to get merged, as at some point android 31 will become a mandatory target.

My only question is, considering the plugin is using intents, should exported be set to true or false? From my understanding it should be true. Why false?

dimitriscsd avatar Jul 22 '22 07:07 dimitriscsd

Yes, it should be true(Copy paste error), I have updated it.

marutifh avatar Jul 22 '22 08:07 marutifh

Made all the changes suggested by marutifh . Build goes successful but Notifications stop getting received. Please suggest.

manojsachdeva avatar Nov 13 '22 12:11 manojsachdeva

I have a forked the plugin and made some changes to it, please use that and check if that works.

On Sun, 13 Nov 2022 at 5:39 PM, manojsachdeva @.***> wrote:

Made all the changes suggested by marutifh https://github.com/marutifh . Build goes successful but Notifications stop getting received. Please suggest.

— Reply to this email directly, view it on GitHub https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated/pull/277#issuecomment-1312715455, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABF25NAVSMP7CNXXEI4P6MTWIDLBHANCNFSM5LOQ225A . You are receiving this because you authored the thread.Message ID: <andrehtissot/cordova-plugin-fcm-with-dependecy-updated/pull/277/c1312715455 @github.com>

marutifh avatar Nov 13 '22 12:11 marutifh

I have the same problem that the device stop getting notifications (after using [email protected] api level 32) but the firebase log shows the device received the message successfully as below: This happens on an Android 12 device. My other Android 10 device acts normally.

{"multicast_id":5201022006522061208,"success":3,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1669088172033212%bee5d517bee5d517"},{"message_id":"0:1669088172015732%bee5d517bee5d517"},{"message_id":"0:1669088172014980%bee5d517bee5d517"}]}

anyone can help?

== update == if the app is in foreground it can call into FCM.onNotification, which says the device does receive the push, it just doesn't show anything in the notification area if the app is in background.

== update2 == saw this in adb log: 11-22 13:32:12.750 3932 7540 D CompatibilityChangeReporter: Compat change id reported: 160794467; UID 10377; state: ENABLED 11-22 13:32:12.757 3932 7540 E AndroidRuntime: FATAL EXCEPTION: Firebase-Messaging-Intent-Handle 11-22 13:32:12.757 3932 7540 E AndroidRuntime: Process: com.phm.smartschool, PID: 3932 11-22 13:32:12.757 3932 7540 E AndroidRuntime: java.lang.IllegalArgumentException: com.phm.smartschool: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. 11-22 13:32:12.757 3932 7540 E AndroidRuntime: 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. 11-22 13:32:12.757 3932 7540 E AndroidRuntime: at android.app.PendingIntent.checkFlags(PendingIntent.java:382) 11-22 13:32:12.757 3932 7540 E AndroidRuntime: at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:465) 11-22 13:32:12.757 3932 7540 E AndroidRuntime: at android.app.PendingIntent.getActivity(PendingIntent.java:451) 11-22 13:32:12.757 3932 7540 E AndroidRuntime: at android.app.PendingIntent.getActivity(PendingIntent.java:415) 11-22 13:32:12.757 3932 7540 E AndroidRuntime: at com.google.firebase.messaging.CommonNotificationBuilder.createContentIntent(com.google.firebase:firebase-messaging@@21.0.0:125) 11-22 13:32:12.757 3932 7540 E AndroidRuntime: at com.google.firebase.messaging.CommonNotificationBuilder.createNotificationInfo(com.google.firebase:firebase-messaging@@21.0.0:27) 11-22 13:32:12.757 3932 7540 E AndroidRuntime: at com.google.firebase.messaging.CommonNotificationBuilder.createNotificationInfo(com.google.firebase:firebase-messaging@@21.0.0:9) 11-22 13:32:12.757 3932 7540 E AndroidRuntime: at com.google.firebase.messaging.DisplayNotification.handleNotification(com.google.firebase:firebase-messaging@@21.0.0:27) 11-22 13:32:12.757 3932 7540 E AndroidRuntime: at com.google.firebase.messaging.FirebaseMessagingService.dispatchMessage(com.google.firebase:firebase-messaging@@21.0.0:55) 11-22 13:32:12.757 3932 7540 E AndroidRuntime: at com.google.firebase.messaging.FirebaseMessagingService.passMessageIntentToSdk(com.google.firebase:firebase-messaging@@21.0.0:34) 11-22 13:32:12.757 3932 7540 E AndroidRuntime: at com.google.firebase.messaging.FirebaseMessagingService.handleMessageIntent(com.google.firebase:firebase-messaging@@21.0.0:27) 11-22 13:32:12.757 3932 7540 E AndroidRuntime: at com.google.firebase.messaging.FirebaseMessagingService.handleIntent(com.google.firebase:firebase-messaging@@21.0.0:17) 11-22 13:32:12.757 3932 7540 E AndroidRuntime: at com.google.firebase.messaging.EnhancedIntentService.lambda$processIntent$0$EnhancedIntentService(com.google.firebase:firebase-messaging@@21.0.0:43) 11-22 13:32:12.757 3932 7540 E AndroidRuntime: at com.google.firebase.messaging.EnhancedIntentService$$Lambda$0.run(Unknown Source:6) 11-22 13:32:12.757 3932 7540 E AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 11-22 13:32:12.757 3932 7540 E AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 11-22 13:32:12.757 3932 7540 E AndroidRuntime: at com.google.android.gms.common.util.concurrent.zza.run(Unknown Source:6) 11-22 13:32:12.757 3932 7540 E AndroidRuntime: at java.lang.Thread.run(Thread.java:920)

nicepeter avatar Nov 22 '22 03:11 nicepeter

Oh I got exactly the same output (about FLAG_IMMUTABLE, only use FLAG_MUTABLE). This became blocker now for releasing new versions as 31 is required in store

@marutifh any chance to help with that?

michal-kroliczek avatar Nov 23 '22 01:11 michal-kroliczek

I think on Android I used this method to get the notification on Tap of notification.

https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated#fcmgetinitialpushpayload

Please check if that helps.

On Wed, 23 Nov 2022 at 6:43 AM, Michał Króliczek @.***> wrote:

Oh I got exactly the same output (about FLAG_IMMUTABLE, only use FLAG_MUTABLE). This became blocker now for releasing new versions as 31 is required in store

— Reply to this email directly, view it on GitHub https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated/pull/277#issuecomment-1324426559, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABF25NGM2ODKNCLBG6YWTK3WJVVULANCNFSM5LOQ225A . You are receiving this because you authored the thread.Message ID: <andrehtissot/cordova-plugin-fcm-with-dependecy-updated/pull/277/c1324426559 @github.com>

marutifh avatar Nov 23 '22 08:11 marutifh

Hi @marutifh . Sorry but we are not on the same page... Link you just gave me is about getting payload in app already. The problem is after chanding target sdk to 31 you will see no notification at all (when your app is not used at the moment, background mode). It is not possible to tap something that is not showing up. It was working till sdk 30. Many pepole report it.

Explicitly specified exported=true/false is fixed and app is building, but it is throwing expections instead of showing push notification. (excatly like 3 comments above:https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated/pull/277#issuecomment-1322998049)

I see exception comes from .CommonNotificationBuilder.createNotificationInfo(com.google.firebase:firebase-messaging@@21.0.0:9)

@nicepeter Did you try to use newer firebase sdk? This is old and probably that the reason for problem. FCM plugin does not use Intents directly.

@marutifh What shoud I do to use newest Firebase SDK? I tried to install plugin with newest bom version and in package.json I do have: "cordova-plugin-fcm-with-dependecy-updated": { "ANDROID_FIREBASE_BOM_VERSION": "31.0.0", "ANDROID_DEFAULT_NOTIFICATION_ICON": "@mipmap/ic_launcher", "ANDROID_FCM_VERSION": "21.0.0", "ANDROID_GOOGLE_SERVICES_VERSION": "4.3.4", "ANDROID_GRADLE_TOOLS_VERSION": "4.1.0" } I changed it to 31 but still 21 is used - what to do do not use ANDROID_FCM_VERSION? I will try in a moment if change it to 31.0.0 fix it

CommonNotificationBuilder

michal-kroliczek avatar Nov 23 '22 08:11 michal-kroliczek

After changing ANDROID_FCM_VERSION to 23.1.0 (newest available) the plugin has compilation errors unfortunatelly:

^ symbol: class FirebaseInstanceId location: package com.google.firebase.iid D:\dev\projects\parking-mobile-2\cordova_android\platforms\android\app\src\main\java\com\gae\scaffolder\plugin\FCMPlugin.java:13: error: cannot find symbol import com.google.firebase.iid.InstanceIdResult; ^ symbol: class InstanceIdResult location: package com.google.firebase.iid D:\dev\projects\parking-mobile-2\cordova_android\platforms\android\app\src\main\java\com\gae\scaffolder\plugin\FCMPlugin.java:182: error: cannot find symbol FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() { ^ symbol: class InstanceIdResult location: class FCMPlugin D:\dev\projects\parking-mobile-2\cordova_android\platforms\android\app\src\main\java\com\gae\scaffolder\plugin\FCMPlugin.java:184: error: cannot find symbol public void onComplete(Task<InstanceIdResult> task) { ^ symbol: class InstanceIdResult D:\dev\projects\parking-mobile-2\cordova_android\platforms\android\app\src\main\java\com\gae\scaffolder\plugin\FCMPlugin.java:182: error: cannot find symbol FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() { ^ symbol: variable FirebaseInstanceId location: class FCMPlugin D:\dev\projects\parking-mobile-2\cordova_android\platforms\android\app\src\main\java\com\gae\scaffolder\plugin\FCMPlugin.java:204: error: cannot find symbol FirebaseInstanceId.getInstance().getInstanceId().addOnFailureListener(new OnFailureListener() { ^ symbol: variable FirebaseInstanceId location: class FCMPlugin D:\dev\projects\parking-mobile-2\cordova_android\platforms\android\app\src\main\java\com\gae\scaffolder\plugin\FCMPlugin.java:227: error: cannot find symbol FirebaseInstanceId.getInstance().deleteInstanceId(); ^

I think plugin needs to use newer Firebase SDK which is not possible due compilation errors

michal-kroliczek avatar Nov 23 '22 09:11 michal-kroliczek

In my fork, I have updated to latest Firebase SDK. Please check that and the previously mentioned link is needed to read the notifications received in background mode.

On Wed, 23 Nov 2022 at 2:50 PM, Michał Króliczek @.***> wrote:

After changing ANDROID_FCM_VERSION to 23.1.0 (newest available) the plugin has compilation errors unfortunatelly:

^ symbol: class FirebaseInstanceId location: package com.google.firebase.iid D:\dev\projects\parking-mobile-2\cordova_android\platforms\android\app\src\main\java\com\gae\scaffolder\plugin\FCMPlugin.java:13: error: cannot find symbol import com.google.firebase.iid.InstanceIdResult; ^ symbol: class InstanceIdResult location: package com.google.firebase.iid D:\dev\projects\parking-mobile-2\cordova_android\platforms\android\app\src\main\java\com\gae\scaffolder\plugin\FCMPlugin.java:182: error: cannot find symbol FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() { ^ symbol: class InstanceIdResult location: class FCMPlugin D:\dev\projects\parking-mobile-2\cordova_android\platforms\android\app\src\main\java\com\gae\scaffolder\plugin\FCMPlugin.java:184: error: cannot find symbol public void onComplete(Task<InstanceIdResult> task) { ^ symbol: class InstanceIdResult D:\dev\projects\parking-mobile-2\cordova_android\platforms\android\app\src\main\java\com\gae\scaffolder\plugin\FCMPlugin.java:182: error: cannot find symbol FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() { ^ symbol: variable FirebaseInstanceId location: class FCMPlugin D:\dev\projects\parking-mobile-2\cordova_android\platforms\android\app\src\main\java\com\gae\scaffolder\plugin\FCMPlugin.java:204: error: cannot find symbol FirebaseInstanceId.getInstance().getInstanceId().addOnFailureListener(new OnFailureListener() { ^ symbol: variable FirebaseInstanceId location: class FCMPlugin D:\dev\projects\parking-mobile-2\cordova_android\platforms\android\app\src\main\java\com\gae\scaffolder\plugin\FCMPlugin.java:227: error: cannot find symbol FirebaseInstanceId.getInstance().deleteInstanceId(); ^

I think plugin needs to use newer Firebase SDK which is not possible due compilation errors

— Reply to this email directly, view it on GitHub https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated/pull/277#issuecomment-1324757280, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABF25NENZLXAQH4J53UHMSDWJXOWPANCNFSM5LOQ225A . You are receiving this because you were mentioned.Message ID: <andrehtissot/cordova-plugin-fcm-with-dependecy-updated/pull/277/c1324757280 @github.com>

marutifh avatar Nov 23 '22 09:11 marutifh

Ok now I got everything working! Thank you so much!

@marutifh you should officialy keep going with this plugin as author dropped it and seems you know how it works ;) I will save your fork for future as I would rely on this original repository.

BTW I do have another problem with it. It works fine until in my config.xml I add <edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android"> <application android:allowBackup="false" /> </edit-config>

So I just need to add android:allowBackup="false".

After doing this and running cordova prepare for android it says: Conflict found, edit-config changes from config.xml will overwrite plugin.xml changes and after this activity that comes with this plugin: <activity android:exported="true" android:launchMode="singleTop" android:name="com.gae.scaffolder.plugin.FCMPluginActivity"> <intent-filter> <action android:name="FCM_PLUGIN_ACTIVITY" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> is simply gone from generated AndroidManifest.xml so after adding plugins currently I have to be carefull and do only 'cordova compile' instead of 'corodva build'.

Any ideas why it reports conflict with such 'edit-config'

michal-kroliczek avatar Nov 23 '22 10:11 michal-kroliczek

Glad to see it's working. I also tried to upgrade firebase messaging lib to 23.1.0, got it compiled but notification not showing. I'm switching to cordova-plugin-firebase-messaging which seems easier and work as intended for my first few tests.

== update == cordova-plugin-firebase-messaging doesn't seem to handle click_action as cordova-plugin-fcm-with-dependecy-updated does, sigh...

== update2 == turns out getting rid of "click_action" in the message property needed by cordova-plugin-fcm-with-dependecy-updated, then it works..

nicepeter avatar Nov 23 '22 21:11 nicepeter

Thanks @marutifh your fork works like a charm on Android 12, API 31

jcgz100 avatar Jul 13 '23 19:07 jcgz100

@4sh Thanks for your fork (https://github.com/4sh/cordova-plugin-fcm-with-dependecy-updated). However during the build process we are receiving the error similar to described above https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated/pull/277#issuecomment-1324757280:

error: cannot find symbol
import com.google.firebase.iid.InstanceIdResult;
                              ^
  symbol:   class InstanceIdResult
  location: package com.google.firebase.iid
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

freescout-helpdesk avatar Aug 23 '23 14:08 freescout-helpdesk

Here is the working SDK 33 (Android 13) fork: https://github.com/inrobin/cordova-plugin-fcm-with-dependecy-updated

It contains updates from https://github.com/marutifh/cordova-plugin-fcm-with-dependecy-updated and https://github.com/4sh/cordova-plugin-fcm-with-dependecy-updated

Please fork it for further development.

inrobin avatar Aug 24 '23 08:08 inrobin