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

Why is My React Native Android Build Failing After Updating to 0.71.0-rc.0?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-12-31 14:37:11412browse

Why is My React Native Android Build Failing After Updating to 0.71.0-rc.0?

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

Since the recent release of React Native version 0.71.0-rc.0, Android build failures have been a common issue for developers, despite no changes in their code.

Potential Failures:

Although the error messages may vary, the underlying cause is typically related to the conflicting versions of the React Native library in the node_modules and the Android build.

Solution:

To resolve this issue, two methods can be implemented:

Method 1:

  1. Navigate to the android directory within your project.
  2. Open the build.gradle file.
  3. Add the following code to the bottom of the file:
buildscript {
    // ...
}

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

Method 2:

  1. Open the android directory and the build.gradle file.
  2. Check if your Gradle supports the exclusiveContent method. If not, add the following code:
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
        }
    }
    // ...  
}

These methods will force Gradle to use the React Native library version from your node_modules directory, resolving the conflicts and allowing your Android build to succeed.

The above is the detailed content of Why is My React Native Android Build 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