React Native Android build failure with different errors without any changes in code for past days due to publish of React Native version 0.71.0-rc.0

The build failures for Android was due to the publish of the React Native version 0.71.0-rc0.

Note: Error may be different but this would be the solution if you are getting android build failures without any changes in code for past two days

before trying these methods please revert back every changes you have done : https://stackoverflow.com/a/74371195/10657559

Method 1

Add this fix to your android -> build.gradle file as follows:

buildscript {
    // ...
}


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

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

Method 2

If your gradle doesn’t support above, then add this to your android -> build.gradle file as follows:

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

Ref: Fix and updates on Android build failures happening since Nov 4th 2022 #35210

Leave a Comment