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

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

Closed
2 of 3 tasks
kdqtech opened this issue Dec 7, 2022 · 18 comments

Comments

@kdqtech
Copy link

kdqtech commented Dec 7, 2022

What happened?

Android 12 recently made it mandatory to use FLAG_IMMUTABLE or FLAG_MUTABLE, this makes the application crash as soon as it's opened.

This is happening when I change my targetSdkversion to 31 / 33

Environment

"react": "17.0.2",
"react-native": "0.66.4",
"react-native-onesignal": "4.5.0",

node : v16.18.1
npm : 8.19.2
yarn : 1.22.19

with Previous version compileSdkVersion and targetSdkVersion it was working fine

Screenshot 2022-12-07 at 6 19 28 PM

After changing compileSdkVersion and targetSdkVersion as below it is not working

Screenshot 2022-12-07 at 6 19 53 PM

Steps to reproduce?

1. Create react native project with 
2. Intigrate onesignal library 
3. run the app

What did you expect to happen?

I expected that app should work properly and should not crash

React Native OneSignal SDK version

api 'com.onesignal:OneSignal:4.8.2'

Which platform(s) are affected?

  • iOS
  • Android

Relevant log output

FATAL EXCEPTION: pool-4-thread-1
                                                                                                    Process: com.packagename, PID: 21167
                                                                                                    java.lang.IllegalArgumentException: com.packagename: 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 androidx.work.impl.utils.ForceStopRunnable.getPendingIntent(ForceStopRunnable.java:285)
                                                                                                    	at androidx.work.impl.utils.ForceStopRunnable.isForceStopped(ForceStopRunnable.java:158)
                                                                                                    	at androidx.work.impl.utils.ForceStopRunnable.forceStopRunnable(ForceStopRunnable.java:185)
                                                                                                    	at androidx.work.impl.utils.ForceStopRunnable.run(ForceStopRunnable.java:103)
                                                                                                    	at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:91)
                                                                                                    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
                                                                                                    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
                                                                                                    	at java.lang.Thread.run(Thread.java:1012)

Code of Conduct

  • I agree to follow this project's Code of Conduct
@daviluisb
Copy link

Captura de Tela 2022-12-07 às 16 28 17

I've got the same problem detected by crashlytics, upgrading compileSdk version from 30 to 31, now my android new version that i spend the entire year working on it isnt recieving any OneSignal notification.

@jkasten2
Copy link
Member

jkasten2 commented Dec 7, 2022

@kdqtech Can you confirm this is correct from your orignal post?

"react-native-onesignal": "4.5.0",

We address Android 12 (targetSdkversion: 31) in the react-native-onesignal 4.0.0 release.

@daviluisb Can yo update to the latest react-native-onesignal 4.x.x SDK? It is required to address this issue, see the migration guide to do so:
https://documentation.onesignal.com/docs/step-by-step-react-native-3x-to-400-upgrade-guide

@daviluisb
Copy link

daviluisb commented Dec 8, 2022

@kdqtech Can you confirm this is correct from your orignal post?

"react-native-onesignal": "4.5.0",

We address Android 12 (targetSdkversion: 31) in the react-native-onesignal 4.0.0 release.

@daviluisb Can yo update to the latest react-native-onesignal 4.x.x SDK? It is required to address this issue, see the migration guide to do so: https://documentation.onesignal.com/docs/step-by-step-react-native-3x-to-400-upgrade-guide

Im currently using "react-native-onesignal": "4.0.6"

and api 'com.onesignal:OneSignal:4.3.0' on build.gradle

@kdqtech
Copy link
Author

kdqtech commented Dec 8, 2022

@kdqtech Can you confirm this is correct from your orignal post?

"react-native-onesignal": "4.5.0",

We address Android 12 (targetSdkversion: 31) in the react-native-onesignal 4.0.0 release.

@daviluisb Can yo update to the latest react-native-onesignal 4.x.x SDK? It is required to address this issue, see the migration guide to do so: https://documentation.onesignal.com/docs/step-by-step-react-native-3x-to-400-upgrade-guide

@jkasten2 First of all Thank you so much for your quick response

We were using "react-native-onesignal": "^4.3.11" when the targetSdkVersion was 30. Everything was working then. Since the time we have changed the targetSdkVersion to 31, the one signal library is not working in both cases (version 4.3.11 and version 4.5.0). To validate the issue, I removed onsignal from my project completely and it worked.

let me add here my all the steps and code here when i have integrate onesignal first time in my App

When i have integrated onesignal first time i have follow below steps

The version of "react-native-onesignal": "^4.3.11",

In settings.gradle

include ':react-native-onesignal'
project(':react-native-onesignal').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-onesignal/android')

In android/app/build.gradle

   manifestPlaceholders = [
            appAuthRedirectScheme: 'myappname,
            onesignal_app_id: 'XXX',     //'XXX' is my onesignal app id that get from onesignal account 
            onesignal_google_project_number: 'REMOTE'
    ]

In Main Application

import com.geektime.rnonesignalandroid.ReactNativeOneSignalPackage;

After intigrating everything i started implemention as below

 OneSignal.setLogLevel(6, 0);
 OneSignal.setAppId('XXX');

 OneSignal.getDeviceState().then((data) => {
      let pushToken = data.userId;
      this.setState({oneSignalToken: pushToken});
 });

And then i am just using my above oneSignalToken in my some of axious api

@jkasten2
Copy link
Member

jkasten2 commented Dec 8, 2022

@kdqtech Thanks for the details. I see in your case the crash is coming from androidx.work.impl.utils.ForceStopRunnable based on your original post. This means for some reason there is an old version of androidx.work:work-runtime being included in your app.

To find out what you can try running one of these to see all the gradle dependences for your Android app.

  1. ./gradlew build --scan
  2. ./gradlew -q dependencies

You can then look up the tree to see what is including work-runtime and update the react native plugin.

If the above doesn't help you could just force update androidx.work:work-runtime by adding it to your build.gradle:

dependencies {
   // Keep other dependencies you have
   implementation('androidx.work:work-runtime:2.7.1')
}

However it is better to find the root plugin downgrading so you don't have to keep this work around.

@daviluisb
Copy link

@kdqtech Can you confirm this is correct from your orignal post?

"react-native-onesignal": "4.5.0",

We address Android 12 (targetSdkversion: 31) in the react-native-onesignal 4.0.0 release.

@daviluisb Can yo update to the latest react-native-onesignal 4.x.x SDK? It is required to address this issue, see the migration guide to do so: https://documentation.onesignal.com/docs/step-by-step-react-native-3x-to-400-upgrade-guide

Well tks alot, with "react-native-onesignal": "^4.5.0", the notification is working, and ive added the implementation('androidx.work:work-runtime:2.7.1') too

@kdqtech
Copy link
Author

kdqtech commented Dec 9, 2022

Thanks @jkasten2 it is resolved by adding anyone option from below in android/app/build.gradle

  1. configurations.all {
    resolutionStrategy { force 'androidx.work:work-runtime:2.7.1' }
    }

  2. def work_version = "2.7.1"
    

    // Force WorkManager 2.7.1 for transitive dependency
    implementation("androidx.work:work-runtime:$work_version") {
    force = true
    }

    Your commands helped me a lot !!

@kdqtech
Copy link
Author

kdqtech commented Dec 9, 2022

this is working fine so closing issue

@kdqtech kdqtech closed this as completed Dec 9, 2022
@jkasten2
Copy link
Member

jkasten2 commented Dec 9, 2022

I won't recommend force locking like this:

configurations.all {
   resolutionStrategy { force 'androidx.work:work-runtime:2.7.1' }
}

As this could break things in the future for you, if OneSignal or another library requires a newer version.

It is safer to do this instead:

implementation('androidx.work:work-runtime:2.7.1') {

This well tell gradle that you require at least this version, but something can still upgrade it in your app if it is a requirement.

@iamrohitagg
Copy link

Why is this issue closed? I am still facing crashes in production with version 4.1.0 and none of the above workarounds solved the issue.

@SEAFromJahu
Copy link

SEAFromJahu commented Mar 21, 2023

On S.O Windows 11: "PS D:\SEA\Cofre\A_Alfa\ProjSEA\Flutter\todo> flutter doctor -v
[√] Flutter (Channel stable, 3.7.7, on Microsoft Windows [versÆo 10.0.22000.1696], locale pt-BR)
• Flutter version 3.7.7 on channel stable at D:\SEA\src\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 2ad6cd72c0 (12 days ago), 2023-03-08 09:41:59 -0800
• Engine revision 1837b5be5f
• Dart version 2.19.4
• DevTools version 2.20.1

[X] Windows Version (Unable to confirm if installed Windows version is 10 or greater)

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
• Android SDK at C:\Users\sea-5\AppData\Local\Android\sdk
• Platform android-33-ext4, build-tools 33.0.2
• Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-9505619)
• All Android licenses accepted.

[X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.5.1)
• Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
• Visual Studio Community 2022 version 17.5.33424.131
• Windows 10 SDK version 10.0.22000.0

[√] Android Studio (version 2022.1)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-9505619)

[√] VS Code (version 1.76.2)
• VS Code at C:\Users\sea-5\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.60.0

[√] Connected device (3 available)
• sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 12 (API 31) (emulator)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [versÆo 10.0.22000.1696]
• Edge (web) • edge • web-javascript • Microsoft Edge 111.0.1661.44

[√] HTTP Host Availability
• All required HTTP hosts are available"
And On method: " Future displayNotification(
{required String title, required String body}) async {
print("doing test");
var androidPlatformChannelSpecifics = const AndroidNotificationDetails(
'your channel id', 'your channel name', 'your channel description',
importance: Importance.max, priority: Priority.high);
var platformChannelSpecifics =
NotificationDetails(android: androidPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.show(
0,
title,
body,
platformChannelSpecifics,
payload: 'Default_Sound',
);
}"
After: "await flutterLocalNotificationsPlugin.show()
0,
title,
body,
platformChannelSpecifics,
payload: 'Default_Sound',
);"
I get:
Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
E/MethodChannel#dexterous.com/flutter/local_notifications(13731): 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.

@nan-li
Copy link
Contributor

nan-li commented Mar 21, 2023

Hi @iamrohitagg, this issue was closed by the original poster as they were able to resolve it. If you are on version 4.1.0, you will need to update. We made the fix to support Android 12 in version 4.3.0 of the react-native-onesignal SDK. Please update to that version or above.

Hi @SEAFromJahu I don't see any mention of onesignal in your post. The message seems to come from flutter/local_notifications

@hdoublin
Copy link

jkasten2
Working!

@wepashka
Copy link

wepashka commented Aug 8, 2023

I have same issue on flutter

@vaish8529
Copy link

vaish8529 commented Sep 11, 2023

I'm using the react-native-share package to share a component as an image. It works fine on Android versions below 33, but on Android 33, it throws an error: 'Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a Pending Intent.' How can I fix this issue?

After updating react-native-share package its says,

react-native-share compile SDK Version is not specified. Please add it to build.gradle.

What went wrong: A problem occurred evaluating project ':react-native-share'.
Could not set unknown property 'namespace' for extension 'android' of type com.android.build.gradle.LibraryExtension.

buildToolsVersion = "33.0.2"
minSdkVersion = 21
compileSdkVersion = 33
targetSdkVersion = 33

On my app/build.gradle file inside dependencies

implementation 'androidx.work:work-runtime:2.7.1'

Still got same error

@husseing-hazzaly
Copy link

FATAL EXCEPTION: main
Process: ru.ironcodes.islamicwikipedia, PID: 6914
java.lang.RuntimeException: Unable to start activity ComponentInfo{ru.ironcodes.islamicwikipedia/ru.ironcodes.islamicwikipedia.MainActivity}: java.lang.IllegalArgumentException: ru.ironcodes.islamicwikipedia: 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.ActivityThread.performLaunchActivity(ActivityThread.java:3760)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3934)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2287)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:210)
at android.os.Looper.loop(Looper.java:299)
at android.app.ActivityThread.main(ActivityThread.java:8261)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1045)
Caused by: java.lang.IllegalArgumentException: ru.ironcodes.islamicwikipedia: 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:375)
at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645)
at android.app.PendingIntent.getBroadcast(PendingIntent.java:632)
at ru.ironcodes.islamicwikipedia.AlarmReceiver.setAlarm(AlarmReceiver.java:29)
at ru.ironcodes.islamicwikipedia.MainActivity.onCreate(MainActivity.java:109)
at android.app.Activity.performCreate(Activity.java:8238)
at android.app.Activity.performCreate(Activity.java:8206)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3733)
... 12 more

@husseing-hazzaly
Copy link

Uploading 111.png…

@Earnchamp
Copy link

me also have same issue how to solve it for sketchware development

java.lang.RuntimeException: Unable to start activity ComponentInfo{ru.ironcodes.islamicwikipedia/ru.ironcodes.islamicwikipedia.MainActivity}: java.lang.IllegalArgumentException: ru.ironcodes.islamicwikipedia: 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.ActivityThread.performLaunchActivity(ActivityThread.java:3760)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3934)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2287)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:210)
at android.os.Looper.loop(Looper.java:299)
at android.app.ActivityThread.main(ActivityThread.java:8261)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1045)
Caused by: java.lang.IllegalArgumentException: ru.ironcodes.islamicwikipedia: 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:375)
at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645)
at android.app.PendingIntent.getBroadcast(PendingIntent.java:632)
at ru.ironcodes.islamicwikipedia.AlarmReceiver.setAlarm(AlarmReceiver.java:29)
at ru.ironcodes.islamicwikipedia.MainActivity.onCreate(MainActivity.java:109)
at android.app.Activity.performCreate(Activity.java:8238)
at android.app.Activity.performCreate(Activity.java:8206)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3733)
... 12 more

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

No branches or pull requests