feat(Expo): add config plugin for managed / prebuild workflow#268
Open
BLOCKMATERIAL wants to merge 1 commit into
Open
feat(Expo): add config plugin for managed / prebuild workflow#268BLOCKMATERIAL wants to merge 1 commit into
BLOCKMATERIAL wants to merge 1 commit into
Conversation
Adds an Expo config plugin that patches AndroidManifest.xml during
`expo prebuild` so the `RNBackgroundActionsTask` service is declared
with the appropriate `android:foregroundServiceType` and the matching
`FOREGROUND_SERVICE_*` runtime permission.
Without this, Expo-managed apps targeting SDK 34+ crash with
`InvalidForegroundServiceTypeException: Starting FGS with type none ...`
because manual edits to AndroidManifest.xml don't survive prebuild.
Usage:
{
"expo": {
"plugins": [
["react-native-background-actions", { "foregroundServiceType": "dataSync" }]
]
}
}
The plugin accepts a string or array of types and defaults to "dataSync".
Values must match the `foregroundServiceType` array passed to
`BackgroundService.start()` at runtime.
- plugin/build/withBackgroundActions.js: runtime entry (CommonJS)
- plugin/src/withBackgroundActions.ts: TypeScript source
- app.plugin.js: Expo plugin entry point
- __tests__/plugin.test.js: smoke tests (5 cases, all passing)
- INSTALL.md: new "Using Expo" section
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an Expo config plugin so
react-native-background-actionsworks out of the box in Expo managed and prebuild workflows.The plugin patches
AndroidManifest.xmlduringexpo prebuildto:com.asterinet.react.bgactions.RNBackgroundActionsTaskservice with the requiredandroid:foregroundServiceTypeattribute.FOREGROUND_SERVICE_*runtime permission(s).Why
Since the 4.1.0 release (#265), users can pass
foregroundServiceTypeat runtime toBackgroundService.start(). However, Android 14+ also requires the service to be declared withandroid:foregroundServiceTypeinAndroidManifest.xml, otherwise apps targetingtargetSdkVersion >= 34crash with:For bare React Native projects this is documented in
INSTALL.md— users edit the manifest manually. In Expo projects this is not possible because the native folders are regenerated byexpo prebuild. Currently every Expo user has to author their own config plugin (the snippet floating around in issues / Stack Overflow). This PR moves that into the package so the Expo experience is zero-config.Usage
{ "expo": { "plugins": [ ["react-native-background-actions", { "foregroundServiceType": "dataSync" }] ] } }"dataSync"when no props are passed.FOREGROUND_SERVICE_*permission automatically for each type.What's in this PR
plugin/build/withBackgroundActions.js— runtime entry (CommonJS, no build step needed at install time).plugin/src/withBackgroundActions.ts— TypeScript source for maintainers / future build pipeline.app.plugin.js— Expo's plugin entry point (auto-resolved by@expo/config-plugins).__tests__/plugin.test.js— 5 smoke tests covering: defaults, single type, multiple types, unknown type rejection, in-place service update.INSTALL.md— new "Using Expo (managed / prebuild workflow)" section.package.json— addsplugin/buildandapp.plugin.jstofiles..gitignore— un-ignoresplugin/build/(the globalbuild/rule was hiding it).@expo/config-pluginsis not added as a dependency. Expo provides it at prebuild time, and the test file mocks it withjest.mock(..., { virtual: true })so unit tests don't require installing it.Test plan
yarn ci(lint + declaration:build + checkjs + test) is green.startForeground().Happy to adjust naming, structure, or split into a separate
expo-config-plugin-*package if you'd prefer not to bundle the plugin with the main package.