React Native Android Build Failures Due to React Native Version 0.71.0-rc.0
Problem:
Recently, users have encountered various errors when building their React Native Android apps, despite not making any code changes. These errors may manifest differently, but they typically involve failed installations or unresolved dependency issues.
Analysis:
Cause:
The root cause of these build failures lies in the recent publication of React Native version 0.71.0-rc.0. This update introduces dependencies that conflict with existing configurations in the Android build system.
Solution:
Method 1:
Modify your Android build.gradle file to force the use of the local React Native library within the node_modules directory. Add the following code:
buildscript { // ... } allprojects { repositories { exclusiveContent { filter { includeGroup "com.facebook.react" } forRepository { maven { url "$rootDir/../node_modules/react-native/android" } } } // ... } }
Method 2:
If your gradle file does not support the exclusiveContent rule, add the following code instead:
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()) buildscript { // ... } allprojects { configurations.all { resolutionStrategy { force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION } } // ... }
Additional Note:
Before applying these fixes, it is recommended to revert any recent changes you have made to your code.
Reference:
For detailed explanations and fixes, please refer to the official update on Android build failures: https://github.com/facebook/react-native/issues/35210
The above is the detailed content of Why are my React Native Android builds failing after upgrading to version 0.71.0-rc.0?. For more information, please follow other related articles on the PHP Chinese website!