Flagged Autolinking
If a feature depends on a native module (e.g. react-native-reanimated), you may want to avoid linking it in builds where the flag is off. This reduces binary size and avoids shipping unused native code.
How it works
Section titled “How it works”During expo prebuild, the config plugin reads which modules should be excluded based on flag state and rewrites the autolinking configuration:
- iOS: modifies the
Podfileto exclude modules from CocoaPods - Android: modifies
settings.gradleto exclude modules from the Gradle build
-
Declare modules on the flag
flags.yml mergePath: src/constants/buildFlags.tsflags:advancedAnimations:value: falsemodules:- react-native-reanimated- react-native-gesture-handlermeta:team: platformWhen
advancedAnimationsisfalse, both modules will be excluded from autolinking. -
Enable flagged autolinking in the config plugin
app.json {"expo": {"plugins": [["expo-build-flags", { "flaggedAutolinking": true }]]}} -
Run prebuild
Terminal window npx expo prebuildThe generated Podfile and settings.gradle will exclude the declared modules.
Allow linking on specific branches
Section titled “Allow linking on specific branches”If you have a CI branch that needs a module linked even when the flag is off (e.g. for integration testing), specify a branch:
flags: advancedAnimations: value: false modules: - react-native-reanimated - react-native-gesture-handler: branch: feature/animations-buildOn the feature/animations-build branch, react-native-gesture-handler will still be linked even though the flag is off. The branch is detected from the CI environment (GITHUB_HEAD_REF or CI_COMMIT_REF_NAME).
Limitations
Section titled “Limitations”- Locally-referenced modules (paths like
./my-module) are not currently supported for exclusion due to upstream constraints inexpo-modules-autolinking. - Only absolute package names are supported.