"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Why are my React Native Android builds failing after upgrading to version 0.71.0-rc.0?

Why are my React Native Android builds failing after upgrading to version 0.71.0-rc.0?

Published on 2024-12-26
Browse:324

Why are my React Native Android builds failing after upgrading to version 0.71.0-rc.0?

React Native Android Build Failures Due to React Native Version 0.71.0-rc.0

Problem:

Recently, users have encountered various errors when building their React Native Android apps, despite not making any code changes. These errors may manifest differently, but they typically involve failed installations or unresolved dependency issues.

Analysis:

Cause:

The root cause of these build failures lies in the recent publication of React Native version 0.71.0-rc.0. This update introduces dependencies that conflict with existing configurations in the Android build system.

Solution:

Method 1:

Modify your Android build.gradle file to force the use of the local React Native library within the node_modules directory. Add the following code:

buildscript {
    // ...
}

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

Method 2:

If your gradle file does not support the exclusiveContent rule, add the following code instead:

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

Additional Note:

Before applying these fixes, it is recommended to revert any recent changes you have made to your code.

Reference:

For detailed explanations and fixes, please refer to the official update on Android build failures: https://github.com/facebook/react-native/issues/35210

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3