-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Emiting Events from HeadlessTask on Android in New Arch + Bridgeless + interop layer #44255
Comments
|
Relevant PR also doublesymmetry/react-native-track-player#2290 |
I can confirm by opting out of bridgeless with RNTP also has a notification no longer working issue as mentioned in the PR mentioned above; this is very puzzling to me because the notification manager component should be purely native. This issue is also "fixed" by opting out of the bridgeless mode. |
Thanks for the confirmation. I believe this has to do with Headless mode not going through the bridgeless initialization mode. We'll look into it and get back to you. |
Thank you @cortinico for looking into this. I am having same issue as well. |
@cortinico any update or ETA on this? |
Sorry I haven't had the time to look into this as we had several tasks with higher priority to look into first. We'll get back to it once we have more free time. |
@contactsimonwilson @lovegaoshi I spent some time investigating this. The outcome is that Line 109 in 33aa83a
We would have to extend the logic there to don't use I've also realized that the library RNTP is in a un-maintained state (maintainers are not responding to PR such as doublesymmetry/react-native-track-player#2290 We should definitely fix Headless tasks in Bridgeless mode, but we're also potentially considering to deprecate this API as it's not widely used and it's probably affected by numerous bugs (for reference, we don't use it internally at Meta at all). I'm curious to hear more use cases for |
hi! really appreciate the work investigating this!
rntp uses headlesstaskservice to provide background playback. while i do
not know the details, rntp made the migration to use headless instead of
extending to MediaLibraryService in 2019. also other background libraries
like react-native-background-timer and react-native-background-actions
depend on headlessJsTaskService. would there be an alternative if this is
removed?
as far I'm aware, rntp is the definitive react native music library with a
notification service. while others are recently providing similar
notification functionalities (expo av, rnvideo), rntp has been doing it
since 2020? and it is way too much migration effort to transition into
other libraries for many, including me. plus, rntp is the only music
library that i know that integrates android auto and carplay. i do agree
the maintenance has been lacking recently but I'm willing to maintain the
android part if necessary. appreciate the work as always!
…On Wed, Jun 12, 2024, 7:37 AM Nicola Corti ***@***.***> wrote:
@contactsimonwilson <https://github.com/contactsimonwilson> @lovegaoshi
<https://github.com/lovegaoshi> I spent some time investigating this.
The outcome is that AppRegistry.registerHeadlessTask is broken on
Bridgeless mode for Android. The reason why it's broken is because of
Headless Tasks are effectively attempting to create a bridge instance
(that's why you see BRIDGE on console).
The problem is here:
https://github.com/facebook/react-native/blob/33aa83a0e6f63d3d50d4803074ad9e2243439100/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/HeadlessJsTaskService.java#L109
We would have to extend the logic there to don't use ReactInstanceManager
if bridgeless is enabled, and instead use ReactHost to start a background
task.
I've also realized that the library RNTP is in a un-maintained state
(maintainers are not responding to PR such as
doublesymmetry/react-native-track-player#2290
<doublesymmetry/react-native-track-player#2290>
So I'm a bit afraid that even if we end up fixing this, the library won't
be releasing a new version in the future.
We should definitely fix Headless tasks in Bridgeless mode, but we're also
potentially considering to deprecate this API as it's not widely used and
it's probably affected by numerous bugs (for reference, we don't use it
internally at Meta at all).
I'm curious to hear more use cases for .registerHeadlessTask to
understand how important is this fix to do.
—
Reply to this email directly, view it on GitHub
<#44255 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AZMOVVS5TUM2PMN2AV2TLNTZHBMK5AVCNFSM6AAAAABGY3XVSWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNRTGE4DGNRTHA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Right now I'm using react-native-background-actions in several projects but the most impacted one is a monitoring app for PEVs (VESC-based onewheels specifically). I use react-native-background actions with react-native-ble-plx, expo-location and expo-av/expo-speech to provide a critical safety monitoring system with data logging and audio/haptic alerts while riding. In its current state, I have a js task that does all that and will stay in the background indefinitely on iOS and Android, even while a device is locked. I would be interested to hear about alternatives for library maintainers. This is the last thing holding me back from upgrading my projects as I can't find other libraries that will work with the new arch and have the same functionality. |
I've put up a draft PR that should fix the issue. Because it is hard to create foreground tasks in new android and test this I will try to build the |
thank you @robik ! I think I applied the patch right but I'm still seeing headlessJsTask going through the bridge, maybe I'm just doing it wrong. NOBRIDGE tag is not applied as in below.
|
You'll have to enable build from source: As Android is prebuilt and the patches for .java files are ignored |
Thanks, I'll try building from source in the next few days. |
I've struggled a couple of times to get a local build without success. Any chance you would be able to provide a build of your PR branch? |
Sadly that's not easily possible as artifacts needs to be published to a repository for this to work. @robik are you blocked on external testing here? As if we merge your changes, @contactsimonwilson and @lovegaoshi will be able to test it with the latest nightly |
@cortinico Hey, I left it as draft because I did not test it (it is more complicated than I thought), because there are some limitations on the usage of headless tasks in android. So it's best to test with the library directly. Unfortunately, I didn't have any time to test it. |
Happy to test as soon as it's in a nightly build 👍 |
It's on the latest nightly: |
next I encountered ndk not specified error. I added local.properties in node_modules/react-native to get pass that.
any help appreciated |
Description
hi! I was directed from reactwg/react-native-new-architecture#8 (reply in thread) to open an issue. I'm looking at RNTP's interop layer compatibility, and there is an issue where the module's hooks using event listeners (with a NOBRIDGE log tag?) are not firing, but listeners registered via AppRegistry.registerHeadlessTask (without the NOBRIDGE log tag?) are. Would anyone share insight on emitting events? Thank you very much in advance
RNTP hooks registering event listeners: here and here
registerHeadlessTask:
logs
Steps to reproduce
React Native Version
0.74
Affected Platforms
Runtime - Android
Areas
Bridgeless - The New Initialization Flow
Output of
npx react-native info
Stacktrace or Logs
Reproducer
https://github.com/lovegaoshi/RNTPExampleNewArch
Screenshots and Videos
No response
The text was updated successfully, but these errors were encountered: