react / react/react-native

HeadlessJS crashes on apps targeting newer Android SDKs

Ouverte
#36,816 18 commentaires 1 réaction 1 personne assignée Voir sur GitHub

@cortinico y travaille déjà.

Depuis le 21/10/2024.

Needs: Triage :mag: Platform: Android Platform: Linux
Langage dominant
C++
Étoiles
127k
Forks
25.3k
Merge moyen
1 j 23 h
PR mergées (30 j)
4

Description

Description

The current HeadlessJS recomendation is to call startService on the passed context as described here

var service = Intent(applicationContext, MyTaskService::class)
applicationContext.startService(service)

This is problematic since Android 8 (SDK 26), there are limitations placed on the background services.
So up until Android 12 (SDK 31) this could have been fixed with something like

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    applicationContext.startForegroundService(service)
} else {
    applicationContext.startService(service)
}

But this will cause issues on apps targeting higher SDKs, since there are additional resrtictions there.

So the latest recommended approach for starting a background service is by using either WorkManager or Coroutines - https://developer.android.com/guide/background#recommended-approaches

React Native Version

0.71.6

Output of npx react-native info

System:
OS: Linux 5.15 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish)
CPU: (8) x64 AMD Ryzen 7 4700U with Radeon Graphics
Memory: 21.18 GB / 38.41 GB
Shell: 5.1.16 - /bin/bash
Binaries:
Node: 16.14.2 - /usr/local/bin/node
Yarn: 1.22.17 - /usr/local/bin/yarn
npm: 8.5.0 - /usr/local/bin/npm
Watchman: 2022.08.15.00 - /home/linuxbrew/.linuxbrew/bin/watchman
SDKs:
Android SDK: Not Found
IDEs:
Android Studio: Not Found
Languages:
Java: 11.0.18 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.2.0 => 18.2.0
react-native: 0.71.6 => 0.71.6
npmGlobalPackages:
react-native: Not Found

Steps to reproduce
  1. Checkout the example app
  2. Build it with yarn start and yarn android
  3. Launch it
  4. The app crashes
Snack, code example, screenshot, or link to a repository

https://github.com/valeri-terziyski/react-native-headless-js-example

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.