Home >Web Front-end >JS Tutorial >Why Are My React Native Android Builds Failing After Updating to 0.71.0-rc.0?

Why Are My React Native Android Builds Failing After Updating to 0.71.0-rc.0?

Susan Sarandon
Susan SarandonOriginal
2024-12-01 21:48:10640browse

Why Are My React Native Android Builds Failing After Updating to 0.71.0-rc.0?

React Native Android Build Errors After Version 0.71.0-rc.0 Release

Recent Android build failures in React Native have been observed, even without code changes. This issue has been attributed to the release of React Native version 0.71.0-rc.0.

Solution

Method 1:

Update your android/build.gradle file with the following:

buildscript {
    // ...
}

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

This forces the resolution of the React Native Android library to use the version from node_modules.

Method 2 (For older Gradle versions):

Add the following to 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())

buildscript {
     // ...
}


allprojects {
    configurations.all {
          resolutionStrategy {
            force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
          }
    }
    // ...  
}

This forces Gradle to use the specified React Native version.

Additional Note:

If you encounter build errors after implementing these solutions, it is recommended to revert any recent code changes and try again.

The above is the detailed content of Why Are My React Native Android Builds Failing After Updating to 0.71.0-rc.0?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn