infobip / mobile-messaging-react-native-plugin

Mobile Messaging SDK plugin for React Native projects
24 stars 4 forks source link

Runtime exception for Android OS v12+ #50

Closed imkrishh closed 1 year ago

imkrishh commented 1 year ago

neact native infobip runtime crash on Android

infobip-mobile-messaging-react-native-plugin -> v6.3.3 react-native -> v0.65.1 compileSdkVersion -> 31 targetSdkVersion -> 31

Fatal Exception: java.lang.IllegalArgumentException: com.bundlex.bundlex: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. 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. at android.app.PendingIntent.checkFlags(PendingIntent.java:382) at android.app.PendingIntent.getActivitiesAsUser(PendingIntent.java:616) at android.app.PendingIntent.getActivities(PendingIntent.java:598) at android.app.PendingIntent.getActivities(PendingIntent.java:545) at org.infobip.mobile.messaging.notification.BaseNotificationHandler.createTapPendingIntent(BaseNotificationHandler.java:230) at org.infobip.mobile.messaging.notification.BaseNotificationHandler.createNotificationCompatBuilder(BaseNotificationHandler.java:117) at org.infobip.mobile.messaging.interactive.notification.InteractiveNotificationHandler.getNotificationBuilder(InteractiveNotificationHandler.java:57) at org.infobip.mobile.messaging.interactive.notification.InteractiveNotificationHandler.displayNotification(InteractiveNotificationHandler.java:44) at org.infobip.mobile.messaging.cloud.MobileMessageHandler.handleMessage(MobileMessageHandler.java:72) at org.infobip.mobile.messaging.mobileapi.messages.MessagesSynchronizer$1.after(MessagesSynchronizer.java:92) at org.infobip.mobile.messaging.mobileapi.messages.MessagesSynchronizer$1.after(MessagesSynchronizer.java:72) at org.infobip.mobile.messaging.mobileapi.common.MRetryableTask$1.after(MRetryableTask.java:92) at org.infobip.mobile.messaging.mobileapi.common.MAsyncTask$2.onPostExecute(MAsyncTask.java:73) at org.infobip.mobile.messaging.mobileapi.common.MAsyncTask$2.onPostExecute(MAsyncTask.java:43) at android.os.AsyncTask.finish(AsyncTask.java:771) at android.os.AsyncTask.access$900(AsyncTask.java:199) at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:788) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.app.ActivityThread.main(ActivityThread.java:8669) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

riskpp commented 1 year ago

Hi @imkrishh, could you please describe which notification are you tapping while receiving this crash? Does it contain browserUrl, webViewUrl or Deeplink? It sounds weird because PendingIntent always contains flag "FLAG_MUTABLE"

rohitsurawat commented 1 year ago

@riskpp this issue is fatal because i am also facing this issue

Exception java.lang.RuntimeException: An error occurred while executing doInBackground() at android.os.AsyncTask$4.done (AsyncTask.java:415) at java.util.concurrent.FutureTask.finishCompletion (FutureTask.java:383) at java.util.concurrent.FutureTask.setException (FutureTask.java:252) at java.util.concurrent.FutureTask.run (FutureTask.java:271) at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:641) at java.lang.Thread.run (Thread.java:920) Caused by java.lang.IllegalArgumentException: at android.app.PendingIntent.checkFlags (PendingIntent.java:377) org.infobip.mobile.messaging.notification.BaseNotificationHandler.createTapPendingIntent

I have one application which is live and we are getting 95% of customer unable to start the application please help here @riskpp

tjuric commented 1 year ago

@rohitsurawat and @imkrishh, please describe your exact use cases which are producing this behaviour. Which payload does notification contain? Do you use any of: browserUrl, webViewUrl or deeplink?

rohitsurawat commented 1 year ago

@tjuric @riskpp 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.

If you read the stack trace it is clearly stating that while passing the flag Strongly Consider FLAG_IMMUTABLE , only use FLAG_MUTABLE in case if your notification have reply or bubble functionality associated to it.

@tjuric if you see @riskpp last reply according to her it will always be "FLAG_MUTABLE" which is wrong in case of simple notifications.

Also in infobip android sdk Class : MobileMessagingProperty have no decleared enum for FLAG_IMMUTABLE .

Check Line no 59 for android sdk

PENDING_INTENT_FLAGS("org.infobip.mobile.messaging.notification.PENDING_INTENT_FLAGS", (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) ? PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_MUTABLE : PendingIntent.FLAG_CANCEL_CURRENT),

Please help us try to resolve this asap we are getting impacted. Also will share the payload that we are sending asap

rohitsurawat commented 1 year ago

@riskpp @tjuric any solution here We are waiting for your response We are sending Simple Plain Text payload in notification which doesn't include any browser url or web url or deep link we don't have such case.

rohitsurawat commented 1 year ago

@tjuric @riskpp any update

riskpp commented 1 year ago

So I've tested it with "WEB_VIEW_URL" (on the tap webView is opening) on Android 12 emulator (31 API) and I can't reproduce any crashes. If talking about newer Android versions, we don't support them for now, but have tasks for that in our backlog and will work on it soon. We will include the possible update for the flag FLAG_MUTABLE to the FLAG_IMMUTABLE, for the cases when push notification doesn't have possibility to be replied to one of the tasks.

riskpp commented 1 year ago

Actually you may try to update react native at least to the 0.68 (I was testing on this) as far as I can see on the documentation, RN started to support 31st Android API from 0.68 version.

rohitsurawat commented 1 year ago

@riskpp We were facing huge volume of crashes due to notifications generated from Infobip Portal so 4 days ago we decide to stop delivery of notification, Since than we have faced 111 crashes in production. And from our testing we came to conclusion that code crash at the time notification is created in Android 12 or Higher mobile. So user will no experience any thing. But our business is impacted due to this.

As i can read your older comment you were saying something about change to FLAG_IMMUTABLE , Can you give us an estimated time when we can expect an infobip library update so that we can update test and release a new version for our customers.

riskpp commented 1 year ago

Hi @rohitsurawat, the crash is connected with the fact that, starting from android 12, mutability flag should be set (and for 6.3.3 plugin version android sdk, which is inside, contains this flag), I didn't notice for all android versions I've tried that mutable flag instead of immutable can lead to the crash (I already tried 0.65 react native version and Android 13 emulator).

Could you please share with us message or campaign id which you've sent and which caused the crashes, you can do it via e-mail if it's preferable. It'll help us to reproduce the issue and resolve it faster.

Thank you!

rohitsurawat commented 1 year ago

@riskpp We have sent email regarding payload and campaign id please check with infobip support team. However we were not able to extract payload or campaign id from portal please provide us clear guide how to extract this info if possible then please respond via email only

rohitsurawat commented 1 year ago

Hi @riskpp @tjuric @mstipanov

As suggested by @riskpp we upgraded the versions.

react native : 0.68.3

Infobip version right now is : infobip-mobile-messaging-react-native-plugin: ^6.3.4

But still same crash we shared earlier is coming. Please help us otherwise we are afraid don't have any other option than dropping your service and choose some other service.

quantumarun commented 1 year ago

@riskpp @mstipanov We need assistance in resolving this as we are facing huge issue from past 1 month. We performed all the changes as said by the Infobip Team but still after releasing the App, we are still facing the issue.

The Crash is only captured in Firebase, Customer doesn't get the Notification on the Device. Notification are not getting delivered, probably failing somewhere in the App during delivery or creating the Notification instance

Caused by java.lang.IllegalArgumentException: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. 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. keyboard_arrow_up

android.app.PendingIntent.checkFlags (PendingIntent.java:382)

arrow_drop_down

android.app.PendingIntent.getActivities (PendingIntent.java:545)

arrow_right

org.infobip.mobile.messaging.notification.BaseNotificationHandler.createTapPendingIntent (BaseNotificationHandler.java:230)

org.infobip.mobile.messaging.notification.BaseNotificationHandler.createNotificationCompatBuilder (BaseNotificationHandler.java:117)

org.infobip.mobile.messaging.interactive.notification.InteractiveNotificationHandler.getNotificationBuilder (InteractiveNotificationHandler.java:57)

org.infobip.mobile.messaging.interactive.notification.InteractiveNotificationHandler.displayNotification (InteractiveNotificationHandler.java:44)

org.infobip.mobile.messaging.cloud.MobileMessageHandler.handleMessage (MobileMessageHandler.java:72)

org.infobip.mobile.messaging.cloud.MobileMessagingCloudHandler.handleMessage (MobileMessagingCloudHandler.java:92)

org.infobip.mobile.messaging.cloud.MobileMessagingCloudHandler.handleWork (MobileMessagingCloudHandler.java:44)

org.infobip.mobile.messaging.cloud.MobileMessagingCloudService.onHandleWork (MobileMessagingCloudService.java:98)

org.infobip.mobile.messaging.platform.JobIntentService$CommandProcessor.doInBackground (JobIntentService.java:415)

org.infobip.mobile.messaging.platform.JobIntentService$CommandProcessor.doInBackground (JobIntentService.java:405)

android.os.AsyncTask$3.call (AsyncTask.java:394)

arrow_drop_down

java.lang.Thread.run (Thread.java:920)

riskpp commented 1 year ago

Hi @quantumarun, @rohitsurawat, Sorry for the delay, we've sent an answer by the e-mail, just to have a followup here:

We’ve check the setup with test application similar to yours and can’t reproduce the issue anyhow. Also we’ve checked your campaign by the provided id and found that you probably have installation of the apps, to which you’ve send the push notifications with version of the react-native plugin, which do not support Android 12 and don’t have the mutability flag set, that could lead to the crash.

BR, Olga

riskpp commented 1 year ago

Hello, just to have a followup here, I'm duplicating my answer from the e-mail

I found one issue on the google issues tracker - https://issuetracker.google.com/issues/194108978?pli=1 When targeting Android S+, some internal androidx libraries still could use an older version of WorkManager which do not use FLAG_IMMUTABLE or FLAG_MUTABLE flag. As a workaround you could try to add the latest version of the WorkManager dependency in your app's build.gradle (android/app/build.gradle) & sync the project.

def work_version = "2.7.0"

// (Java only) implementation "androidx.work:work-runtime:$work_version"

// Kotlin + coroutines implementation "androidx.work:work-runtime-ktx:$work_version"

@quantumarun , @rohitsurawat , Could you please clarify, have you managed to resolve the issue by that advice or it still persists?

riskpp commented 1 year ago

@quantumarun , @rohitsurawat , Could you please clarify, have you managed to resolve the issue by that advice or it still persists?

riskpp commented 1 year ago

We've released actually the change to the FLAG_IMMUTABLE where mutability not required, but still It might be not the reason of why this appears https://github.com/infobip/mobile-messaging-react-native-plugin/releases/tag/6.3.6

imsugat commented 1 year ago

Hi @riskpp,

I am also facing the same issue and have tried the fix suggested in #issuecomment-1269770779 but it's not working. I am getting this crash in Google Crashlytics so not able to capture the notification payload.

infobip-mobile-messaging-react-native-plugin -> v6.3.5 react-native -> v0.66.5 compileSdkVersion -> 31 targetSdkVersion -> 31

riskpp commented 1 year ago

Hi @imsugat are you sure that the user which got the crash updated the version? I can reproduce this crash only if user has Android 12 and version of the plugin, which doesn't support Android 12 ( < 6.0.0).

riskpp commented 1 year ago

I've just found one possible edge case when it could happen:

  1. User updated the application from the version without Android 12 support to the version with Android 12 support (plugin version > 6.0.0) and never run the app (mobilemesaging.init wasn't called).
  2. Application received notification when it's is killed
  3. mobilemesaging.init wasn't called on the background when notification arrived

In this case might happen that property for PendingIntent flags, saved in the Preferences wasn't updated to the new one (which contains FLAG_IMMUTABLE). We'll try to fix that, but before you from your side could try to be sure that you calling mobilemessaging.init if application is started by receiving the push notification.

riskpp commented 1 year ago

Version with possible fix is released https://github.com/infobip/mobile-messaging-react-native-plugin/releases/tag/7.0.3

Check the Migration guide if you updating from 6.x to 7.x

imsugat commented 1 year ago

Hi @riskpp I have tried updating the version of the Infobip plugin in app to 7.0.3 as suggested. While updating I am getting cli error

npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: npm ERR! Found: react-native@0.66.5 npm ERR! node_modules/react-native npm ERR! react-native@"0.66.5" from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer react-native@">=0.68.0 <1.0.x" from infobip-mobile-messaging-react-native-plugin@7.0.3 npm ERR! node_modules/infobip-mobile-messaging-react-native-plugin npm ERR! infobip-mobile-messaging-react-native-plugin@"7.0.3" from the root project npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force, or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

Same issue I have shared via mail.

alboldy-ib commented 1 year ago

Hello, The version with the fix requires React Native version 0.68. Please update your application's dependencies to it.

riskpp commented 1 year ago

Version with fix was released, can be reopened in case of any other issues