Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Android SDK 31 #277

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open

Conversation

marutifh
Copy link

@marutifh marutifh commented Jan 7, 2022

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.

Activity with intent need to have exported mentioned explicitly https://developer.android.com/guide/topics/manifest/activity-element#exported
Support for Android SDK 31 - specify an explicit value for android:exported
@dimitriscsd
Copy link

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?

@marutifh
Copy link
Author

marutifh commented Jul 22, 2022

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

@manojsachdeva
Copy link

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

@marutifh
Copy link
Author

marutifh commented Nov 13, 2022 via email

@nicepeter
Copy link

nicepeter commented Nov 22, 2022

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)

@michal-kroliczek
Copy link

michal-kroliczek commented Nov 23, 2022

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?

@marutifh
Copy link
Author

marutifh commented Nov 23, 2022 via email

@michal-kroliczek
Copy link

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:#277 (comment))

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
Copy link

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

@marutifh
Copy link
Author

marutifh commented Nov 23, 2022 via email

@michal-kroliczek
Copy link

michal-kroliczek commented Nov 23, 2022

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'

@nicepeter
Copy link

nicepeter commented Nov 23, 2022

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..

@jcgz100
Copy link

jcgz100 commented Jul 13, 2023

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

@freescout-helpdesk
Copy link

@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 #277 (comment):

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.

@inrobin
Copy link

inrobin commented Aug 24, 2023

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.

marutifh and others added 5 commits August 28, 2023 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants