close

[Solved] Cannot choose between the following variants of com.facebook.react:react-native:0.71.0-rc.0:

To solve Cannot choose between the following variants of com.facebook.react:react-native:0.71.0-rc.0: error you need to add resolutionStrategy in your android/build.gradle file in allprojects.configurations.all will resolve this error.

Solution 1: Add resolutionStrategy

You need to use React Native version From your node_modules folder. To do so you need to add resolutionStrategy in your android/build.gradle as given below.

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
          }
    }
     ......
     ......
     ......  
}

And now, sync this Gradle file and then rebuild your React Native app and now you will no longer face the above error.

Solution 2: add exclusiveContent

If resolutionStrategy.force not worked for you then You need to add exclusiveContent in your allprojects.repositories.exclusiveContent in your android/build.gradle file.

buildscript {
     ......
     ......
     ......
}
    
    
allprojects {
    repositories {
        google()
         exclusiveContent {
             filter {
                 includeGroup "com.facebook.react"
             }
             forRepository {
                 maven {
                     url "$rootDir/../node_modules/react-native/android"
                 }
             }
         }
       
       }
     ......
     ......
     ......  
}

Now, Sync your Gradle file and then re-run your project will resolve this error.

Solution 3: Update React-native version

As You know React-native released its latest version so it’s better to update it to the latest version. You can read the full official guide about Upgrading to new versions

Conclusion

You need to add resolutionStrategy.force to use react-native version from node_modules will resolve this error OR You need to add exclusiveContent in your allprojects.repositories.exclusiveContent in your android/build.gradle file will resolve this error.

Also, Read

Leave a Comment