Resolving React Native Android Build Failures Due to React Native 0.71.0-rc.0 Release
Problem Statement
After November 4, 2022, many React Native developers encountered unexpected Android build failures without making any code changes. A typical error appears during Gradle dependency resolution:
FAILURE: Build failed with an exception.
* Where: Build file '/path/to/node_modules/react-native-month-year-picker/android/build.gradle' line: 115
* What went wrong:
Could not resolve com.facebook.react:react-native:+.
> Cannot choose between the following variants of com.facebook.react:react-native:0.71.0-rc.0:
- debugVariantDefaultRuntimePublication
- releaseVariantDefaultRuntimePublication
This issue occurs because **third-party libraries using implementation 'com.facebook.react:react-native:+'** started resolving to the newly published
0.71.0-rc.0` in public repositories instead of your locally installed version. The conflict causes Gradle resolution failures and Kotlin version mismatches.
Why This Happens
Background
- React Native
0.71.0-rc.0
was published to MavenCentral on November 4, 2022 - Many third-party libraries declare dependency using
+
(latest version) - Before this release, the only available version was in your
node_modules
folder - After publication, Gradle started seeing two conflicting versions
Your Android build fails because:
- A library declares
implementation 'com.facebook.react:react-native:+'
- Gradle finds both:
- Your project's version in
node_modules
- The new
0.71.0-rc.0
in MavenCentral
- Your project's version in
- Gradle can't automatically choose between them
- Kotlin version conflicts appear when mismatched React Native versions are used
WARNING
This affects projects regardless of their React Native version! The issue stems from library dependencies, not your direct project dependencies.
Recommended Solutions
Solution 1: Exclusive Content Resolution (Preferred)
Add Gradle rules to force resolution through your local node_modules
:
- Open
android/build.gradle
- Add this inside the
allprojects.repositories
block:
allprojects {
repositories {
exclusiveContent {
filter { includeGroup "com.facebook.react" }
forRepository {
maven { url "$rootDir/../node_modules/react-native/android" }
}
}
// Your existing repositories (keep these)
mavenCentral()
google()
}
}
How This Works
The exclusiveContent
rule:
- Targets only
com.facebook.react
group packages - Forces resolution exclusively through your
node_modules
- Prevents Gradle from checking other repositories for React Native artifacts
Solution 2: Force React Native Version (For Older Gradle)
For projects using Gradle versions without exclusiveContent
:
def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim()
allprojects {
configurations.all {
resolutionStrategy.force "com.facebook.react:react-native:$REACT_NATIVE_VERSION"
}
}
Compatibility
This method works for all Gradle versions but is less precise than Solution 1 as it doesn't protect against all conflict scenarios.
Solution 3: Upgrade to Patched React Native Version
The React Native team released patched versions for older release lines. Upgrade to these specific versions:
Your Version | Upgrade Target |
---|---|
0.63.x | 0.63.5 |
0.64.x | 0.64.4 |
0.65.x | 0.65.2 |
0.66.x | 0.66.5 |
0.68.x | 0.68.7 |
0.69.x | 0.69.11 |
0.70.x | 0.70.8 |
Update using npm/yarn:
npm install react-native@x.y.z
# or
yarn add react-native@x.y.z
Post-Solution Steps
After implementing any fix:
- Clean Gradle caches:bash
cd android ./gradlew clean
- Refresh dependencies:bash
npm install # or yarn install
- Rebuild your project:bash
npx react-native run-android
Why Not Specify Exact Library Versions?
While tempting, modifying library dependencies isn't recommended:
// Avoid this approach in libraries' build.gradle
implementation 'com.facebook.react:react-native:0.69.5'
- Breaks library compatibility with future React Native versions
- Requires manual tracking of every dependency
- Causes cascading dependency conflicts
- Loses automatic patch version compatibility
Additional Considerations
- Kotlin version conflicts might persist until resolution strategies are applied
- Hermes users: Both solutions work regardless of Hermes configuration
- Flipper users: No special actions required beyond these fixes
Use Solution 1 for newer projects with modern Gradle setups. Solution 2 provides compatibility for legacy environments. Solution 3 offers a long-term fix while keeping dependencies current. For ongoing maintenance, prefer Solution 1 for cleanest resolution behavior.