yasirkula / UnityNativeShare

A Unity plugin to natively share files (images, videos, documents, etc.) and/or plain text on Android & iOS
MIT License
890 stars 131 forks source link

SDK 31 above requires FLAG_IMMUTABLE or FLAG_MUTABLE PendingIntent. #166

Open seilron opened 1 year ago

seilron commented 1 year ago

Description of the bug

2023/02/20 17:23:03.310 21577 21577 Error AndroidRuntime java.lang.IllegalArgumentException: com.com2us.futurecpb.android.google.global.normal: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. 2023/02/20 17:23:03.310 21577 21577 Error 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. 2023/02/20 17:23:03.310 21577 21577 Error AndroidRuntime at android.app.PendingIntent.checkFlags(PendingIntent.java:382) 2023/02/20 17:23:03.310 21577 21577 Error AndroidRuntime at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:673) 2023/02/20 17:23:03.310 21577 21577 Error AndroidRuntime at android.app.PendingIntent.getBroadcast(PendingIntent.java:660) 2023/02/20 17:23:03.310 21577 21577 Error AndroidRuntime at com.yasirkula.unity.NativeShareBroadcastListener.Initialize(NativeShareBroadcastListener.java:32) 2023/02/20 17:23:03.310 21577 21577 Error AndroidRuntime at com.yasirkula.unity.NativeShareFragment.onCreate(NativeShareFragment.java:42) 2023/02/20 17:23:03.310 21577 21577 Error AndroidRuntime at android.app.Fragment.performCreate(Fragment.java:2486) 2023/02/20 17:23:03.310 21577 21577 Error AndroidRuntime at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1261) 2023/02/20 17:23:03.310 21577 21577 Error AndroidRuntime at android.app.FragmentManagerImpl.addAddedFragments(FragmentManager.java:2431) 2023/02/20 17:23:03.310 21577 21577 Error AndroidRuntime at android.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2210) 2023/02/20 17:23:03.310 21577 21577 Error AndroidRuntime at android.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2166) 2023/02/20 17:23:03.310 21577 21577 Error AndroidRuntime at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2067) 2023/02/20 17:23:03.310 21577 21577 Error AndroidRuntime at android.app.FragmentManagerImpl$1.run(FragmentManager.java:742) 2023/02/20 17:23:03.310 21577 21577 Error AndroidRuntime at android.os.Handler.handleCallback(Handler.java:938) 2023/02/20 17:23:03.310 21577 21577 Error AndroidRuntime at android.os.Handler.dispatchMessage(Handler.java:99) 2023/02/20 17:23:03.310 21577 21577 Error AndroidRuntime at android.os.Looper.loopOnce(Looper.java:226) 2023/02/20 17:23:03.310 21577 21577 Error AndroidRuntime at android.os.Looper.loop(Looper.java:313) 2023/02/20 17:23:03.310 21577 21577 Error AndroidRuntime at android.app.ActivityThread.main(ActivityThread.java:8669) 2023/02/20 17:23:03.310 21577 21577 Error AndroidRuntime at java.lang.reflect.Method.invoke(Native Method) 2023/02/20 17:23:03.310 21577 21577 Error AndroidRuntime at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571) 2023/02/20 17:23:03.310 21577 21577 Error AndroidRuntime at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

Reproduction steps

need Android OS 12~ Build SDK 31~ Excute and Share

Platform specs

Unity version : 2021.3.16f1 Platform : Android Device : Android OS 12~ Plugin Download Path - Github

yasirkula commented 1 year ago

Can you delete NativeShare from your project, comment out NativeShare related user code and build again? "com.com2us.futurecpb.android.google.global.normal" isn't a part of this plugin.

EduFeArn commented 1 year ago

Hi, I am having the same issue see details bellow:

FATAL EXCEPTION: main Process: com.EduFeArn.EduFeArnEduGames, PID: 5408

java.lang.IllegalArgumentException: com.EduFeArn.EduFeArnEduGames: 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.getBroadcastAsUser(PendingIntent.java:673) at android.app.PendingIntent.getBroadcast(PendingIntent.java:660) at com.yasirkula.unity.NativeShareBroadcastListener.Initialize(NativeShareBroadcastListener.java:33) at com.yasirkula.unity.NativeShareFragment.onCreate(NativeShareFragment.java:42) at android.app.Fragment.performCreate(Fragment.java:2486) at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1261) at android.app.FragmentManagerImpl.addAddedFragments(FragmentManager.java:2431) at android.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2210) at android.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2166) at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2067) at android.app.FragmentManagerImpl$1.run(FragmentManager.java:742) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.app.ActivityThread.main(ActivityThread.java:8663) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

Reproduction need Android OS 12 Build SDK 32 At runtime when attempting to Share

Platform Unity version : 2020.3.41f1 Platform : Android Device : Android OS 12

Have confirmed that building and targeting any API level below 31 does not cause this to happen

yasirkula commented 1 year ago

I'm passing FLAG_MUTABLE's hardcoded value which is why I'm having trouble figuring out this issue: https://github.com/yasirkula/UnityNativeShare/blob/a23ce3ea293ceebf4a78ddcbefdcd9591d6e164d/.github/AAR%20Source%20(Android)/java/com/yasirkula/unity/NativeShareBroadcastListener.java#L23-L30

EduFeArn commented 1 year ago

I do apologize for any inconvenience, seems the issue was on my side removed and reimported the plug-in and is working. Recently did a big upgrade in unity versions, the version of the plug-in was also most likely out of date and I did not notice, Thanks again for the help and again apologies.

yasirkula commented 1 year ago

Happy to help :D

yasirkula commented 1 year ago

Reopened because @seilron hasn't responded yet. Please upgrade the plugin via GitHub and try again.