In this lesson, you will learn how to identify and resolve "dependency hell" when native modules conflict during your Expo build process.
When you add third-party libraries to a cross-platform project, you aren't just adding JavaScript code; you are often pulling in native Android (.java/.kt) and iOS (.m/.swift) files. Sometimes, two different libraries might expect different versions of a shared native dependency (like a specific version of Google Play Services or an iOS CocoaPod), leading to a "build-time collision."
Spotting the Conflict
If your npx expo run:android or npx expo run:ios command fails with cryptic errors about duplicate symbols or mismatched versions, your dependency tree is likely tangled.
The first step in troubleshooting is to visualize your dependencies. Use the terminal command:
npm list <package-name>
This shows you which version is installed and what other package requested it. If you see two different versions of the same native SDK, you have found your conflict.
Resolving the Issue
When conflicts arise in the Expo ecosystem, we don't manually edit the native folders (as that defeats the purpose of the Expo workflow). Instead, we use Config Plugins.
If a library requires a specific native version, you can often override it in your app.json or app.config.js. For example, if you need to force a specific Android Gradle version to resolve a conflict, you would add it to your plugins:
{
"expo": {
"plugins": [
[
"expo-build-properties",
{
"android": {
"compileSdkVersion": 34
}
}
]
]
}
}
By using expo-build-properties, you instruct the prebuild process to generate native project files that align all your libraries to a compatible version. If a library is completely broken, you may need to use patch-package to fix the underlying dependency definition in your node_modules—though always try to resolve it via plugins first to keep your project maintainable.
Key Takeaway: Always resolve native dependency conflicts by using Expo Config Plugins to adjust the build environment, rather than modifying native source code directly.