There are some issues in the react-native itself.
the solution to this issue - [https://github.com/facebook/react-native/issues/35210][1]
For react-native ( >= 0.63)
In **android -> build.gradle** add this exclusive Content inside the allprojects.repositories
allprojects {
repositories {
exclusiveContent {
// We get React Native's Android binaries exclusively through npm,
// from a local Maven repo inside node_modules/react-native/.
// (The use of exclusiveContent prevents looking elsewhere like Maven Central
// and potentially getting a wrong version.)
filter {
includeGroup "com.facebook.react"
}
forRepository {
maven {
url "$rootDir/../node_modules/react-native/android"
}
}
}
// ...
}
}
For older react-native (< 0.63)
Add this in the all projects area of your **android -> build.gradle** file.
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 {
// Remove this override in 0.65+, as a proper fix is included in react-
native itself.
force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
}
}
[1]: https://github.com/facebook/react-native/issues/35210
**If you face the issue from Nov 4th 2022,**
**Fix for react-native >= 0.63 and lower than 0.67**
In `android/buld.gradle` file,
<!-- language: lang-html -->
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
// ...
}
allprojects {
repositories {
+ exclusiveContent {
+ // We get React Native's Android binaries exclusively through npm,
+ // from a local Maven repo inside node_modules/react-native/.
+ // (The use of exclusiveContent prevents looking elsewhere like Maven Central
+ // and potentially getting a wrong version.)
+ filter {
+ includeGroup "com.facebook.react"
+ }
+ forRepository {
+ maven {
+ // NOTE: if you are in a monorepo, you may have "$rootDir/../../../node_modules/react-native/android"
+ url "$rootDir/../node_modules/react-native/android"
+ }
+ }
+ }
// ...
}
}
<!-- end snippet -->
What this fix will do is apply an exclusiveContent resolution rule that will force the resolution of React Native Android library, to use the one inside node_modules.
Once you update your app to React Native v0.71.0, this fix won't be needed anymore.
**Fix for older react-native (< 0.63)**
The fix above only works on gradle 6.2 and higher. Older react-native used older gradle.
You may determine your gradle version by looking in your [/android/gradle/wrapper/gradle-wrapper.properties][1] file.
If you are on older react-native (for example 0.63 or earlier) that uses gradle version 6.1 or below, you must use a different workaround, detailed here: [#35210 (comment)][2]
[1]: https://github.com/facebook/react-native/blob/main/template/android/gradle/wrapper/gradle-wrapper.properties
[2]: https://github.com/facebook/react-native/issues/35210#issuecomment-1304536693
***Updated On Nov 11th 2022***
If the above solution is not working for you then try this one.
In `android/buld.gradle` file,
<!-- language: lang-js -->
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 {
// Remove this override in 0.66, as a proper fix is included in react-native itself.
force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
}
}
// ...
}
<!-- end snippet -->