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

Android 12 not receving expo-notifications correctly #16678

Closed
Tythiras opened this issue Mar 17, 2022 · 14 comments
Closed

Android 12 not receving expo-notifications correctly #16678

Tythiras opened this issue Mar 17, 2022 · 14 comments

Comments

@Tythiras
Copy link

Tythiras commented Mar 17, 2022

Summary

Upon sending notifications to an app using android SDK 31 the notifications never appear on the mobile phone.
The Notifications.addNotificationReceivedListener is still called, but notification is never shown in the UI.

Also the Notifications.scheduleNotificationAsync results in Error: Failed to schedule notification.
This is to my knowledge only happening on android 12.

Downgrading to SDK 30 makes notification work as expected again.

Tested with Poco F3, MIUI Global 13.0.3

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

bare

What platform(s) does this occur on?

Android

SDK Version (managed workflow only)

44.0.6

Environment

expo-env-info 1.0.2 environment info:
System:
OS: Linux 5.15 Manjaro Linux
Shell: 5.8 - /usr/bin/zsh
Binaries:
Node: 14.17.0 - ~/.nvm/versions/node/v14.17.0/bin/node
Yarn: 1.22.17 - /usr/bin/yarn
npm: 6.14.13 - ~/.nvm/versions/node/v14.17.0/bin/npm
SDKs:
Android SDK:
API Levels: 29, 30, 31
Build Tools: 28.0.3, 29.0.2, 30.0.3
System Images: android-30 | Google APIs Intel x86 Atom
npmPackages:
expo: ~44.0.0 => 44.0.6
react: 17.0.1 => 17.0.1
react-dom: 17.0.1 => 17.0.1
react-native: 0.64.3 => 0.64.3
react-native-web: 0.17.1 => 0.17.1
Expo Workflow: bare

Reproducible demo

Setting up a new bare workflow with
expo init test-notifications
expo eject

Installing / Setting up expo notifications
expo install expo-notifications
And following: https://docs.expo.dev/guides/setup-native-firebase/#bare-workflow-setup
Inserting the example from https://docs.expo.dev/versions/latest/sdk/notifications/ in App.js

Upgrading android SDK in root build.gradle

buildscript {
    ext {
        buildToolsVersion = "29.0.3"
        minSdkVersion = 21
        compileSdkVersion = 31
        targetSdkVersion = 31
    }
    ...
}

And adding android:exported="true" to AndroidManifest.xml under .MainActivity, activity tag.

Now the issue can be reproduced by either pressing the schedule notification button or sending a notification to the push token, for example through the expo push notification tool.

@Tythiras Tythiras added the needs validation Issue needs to be validated label Mar 17, 2022
@byCedric byCedric added Android Notifications bug and removed needs validation Issue needs to be validated labels Mar 21, 2022
@ahmedsamirdev
Copy link

I got this error On SDK 44 (expo-managed)- Test on (MIUI 12)
My code snack give this error msg [Unhandled promise rejection: Error: Failed to schedule notification.] when I set trigger with seconds but if I make it null it will shows notification and make vibration but with no sound

Expected behavior: Make sound after 5 seconds.

@txvnt
Copy link

txvnt commented Apr 7, 2022

I had this issue, the error message is not very helpful but you'll probably will find more information with Logcat or something like that. For me, the actual error came up using Android Studio's logcat:

Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified

Turns out that my compileSdkVersion and targetSdkVersion were set both to 31. I set them to 30, ran ./gradlew clean, rebuilt the app, and then my notifications started working correctly again.

I hope this helps.

@ourmaninamsterdam
Copy link

@txvnt We're experiencing the same issue. Can confirm that after setting both compileSdkVersion and targetSdkVersion to 30 the notifications are working correctly.

@ourmaninamsterdam
Copy link

@txvnt We're experiencing the same issue. Can confirm that after setting both compileSdkVersion and targetSdkVersion to 30 the notifications are working correctly.

We are on Expo SDK 43, bare workflow. After reverting to compileSdkVersion and targetSdkVersion 31, we ended up patching expo-notifications with patches from #17334 and #17333

@EduGomes18
Copy link

i`m on expo sdk 45 compileSdkVersion 31 and targetSdkVersion 31, started receiving the bad error "Failed to schedule notification"

@qhoarau
Copy link

qhoarau commented Jun 8, 2022

I have the same issue, notifications are not received on my android 12 Xiaomi 11 lite, MIUI Global 13.0.8
Is there any workaround ?

@mmkhmk
Copy link

mmkhmk commented Jun 20, 2022

I'm facing the same issue: receiving the error "Failed to schedule notification" with compileSdkVersion 31 and targetSdkVersion 31. Any solutions?

@keech
Copy link

keech commented Jun 20, 2022

@txvnt We're experiencing the same issue. Can confirm that after setting both compileSdkVersion and targetSdkVersion to 30 the notifications are working correctly.

@mmkhmk Have you tried above?

@mmkhmk
Copy link

mmkhmk commented Jun 20, 2022

@txvnt We're experiencing the same issue. Can confirm that after setting both compileSdkVersion and targetSdkVersion to 30 the notifications are working correctly.

@mmkhmk Have you tried above?

Yes, I tried it and it works with compileSdkVersion and targetSdkVersion 30.
I didn't find any no other solution so far.

@keech
Copy link

keech commented Jun 20, 2022

@txvnt We're experiencing the same issue. Can confirm that after setting both compileSdkVersion and targetSdkVersion to 30 the notifications are working correctly.

@mmkhmk Have you tried above?

Yes, I tried it and it works with compileSdkVersion and targetSdkVersion 30.

I didn't find any no other solution so far.

Setting 30 version seems to be the temporary solution so far

@txvnt
Copy link

txvnt commented Jun 20, 2022

Since the error I was getting was Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when I found the temporary solution, maybe there's a way to fix this without downgrading sdk versions directly on the Android project, but unfortunately I'm not expert at Android native development.

I will try this evening though, maybe I'm lucky.

@m-jachym
Copy link

Same issue.
Main problem is, that can't go back to version 30, cause while doing that other packages won't run on android 12 so it looks like I'm stuck and unable to release to play store until expo-notifications will be updated 😢 😢 😢

@brentvatne
Copy link
Member

if you are using android sdk 30, you should use expo sdk 44. if you are using android sdk 31, you should use expo sdk 45. https://blog.expo.dev/expo-sdk-45-f4e332954a68

@ourmaninamsterdam
Copy link

If you're using Expo SDK 43 (and cannot upgrade yet), we were able to resolve this by patching expo-notifications with changes from these PRs: #17334 and #17333. These can be applied as a post-install patch using patch-package. Here's the patch: https://gist.github.com/ourmaninamsterdam/bf02b263c9a7aabca838ce21a1f9f6df

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests