Home > Software design >  Android build failures happening since 4th Nov 2022[FIX INSIDE]
Android build failures happening since 4th Nov 2022[FIX INSIDE]

Time:11-09

The build error looks something like this:

Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

  • What went wrong: A problem occurred configuring root project 'My Project'. Could not determine the dependencies of null. Could not resolve all task dependencies for configuration ':classpath'.

    Could not resolve com.facebook.react:react-native: . Required by: project : No matching variant of com.facebook.react:react-native:0.71.0-rc.0 was found. The consumer was configured to find a runtime of a library compatible with Java 11, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.3.3'

CodePudding user response:

update this below content in project level build.gradle:

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

it's working for me

CodePudding user response:

FIX INSIDE

Steps to resolve the react-native issue that we are facing since couple of days.

  1. Goto package.json and upgrade the react-native version to 0.64.4.(or whatever the supported version we have on the GitHub thread)
  2. Run yarn install.
  3. Now cd android
  4. ./gradlew clean
  5. cd ..
  6. yarn android (now your project will execute properly)

Note: This issue occurred because of the new release of the react native(4th nov), here I'm attaching the link for the reference.

URL : https://github.com/facebook/react-native/issues/35210

(if you face any issues do let me know i'll help you in resolving the same.)

CodePudding user response:

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

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

https://github.com/facebook/react-native/issues/35204#issuecomment-1304281740

CodePudding user response:

This fix works:

Reason for Failures : The build failures for Android was due to the publish of the React Native version 0.71.0-rc0 to Maven and because of which when the gradle is syncing its picking this 0.71.0-rc0 version of react-native rather then your current version of react-native.

Made it work without upgrading react-native version and by adding this in build.gradle, this works (hermes enabled or not, along with flipper too)

 exclusiveContent {
            // We get React Native's Android binaries exclusively through npm,
            // from a local Maven repo inside node_modules/react-native/.
            // (The use of exclusiveContent prevents looking elsewhere like Maven Central
            // and potentially getting a wrong version.)
            filter {
                includeGroup "com.facebook.react"
            }
            forRepository {
                maven {
                    url "$rootDir/../node_modules/react-native/android"
                }
            }
        }

final snippet looks like this

allprojects {
    repositories {
        exclusiveContent {
            // We get React Native's Android binaries exclusively through npm,
            // from a local Maven repo inside node_modules/react-native/.
            // (The use of exclusiveContent prevents looking elsewhere like Maven Central
            // and potentially getting a wrong version.)
            filter {
                includeGroup "com.facebook.react"
            }
            forRepository {
                maven {
                    url "$rootDir/../node_modules/react-native/android"
                }
            }
        }
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")

gradle clean and rebuild after this fix. Then you can react native run android successfully.

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

If you dont want to put this fix, you can update your react native version for the project to the react native patch version as mentioned here

https://github.com/facebook/react-native/issues/35210

  • Related