Home > database >  React Native Android build failure with different errors without any changes in code for past days d
React Native Android build failure with different errors without any changes in code for past days d

Time:11-08

Note: Error may be different but if you are getting any error when taking android build without any changes in code for past two days

My Error - Failed to install the app. Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

error Failed to install the app. Make sure you have the Android development environment set up:

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

FAILURE: Build failed with an exception.

* Where: Build file '/Users/....../node_modules/react-native-month-year-picker/android/build.gradle' line: 115

* What went wrong: A problem occurred configuring project ':react-native-month-year-picker'.

> Could not resolve all files for configuration ':react-native-month-year-picker:implementation'.
   > Could not resolve com.facebook.react:react-native: .
     Required by:
         project :react-native-month-year-picker
      > Cannot choose between the following variants of com.facebook.react:react-native:0.71.0-rc.0:
          - debugVariantDefaultRuntimePublication
          - releaseVariantDefaultRuntimePublication
        All of them match the consumer attributes:
          - Variant 'debugVariantDefaultRuntimePublication' capability com.facebook.react:react-native:0.71.0-rc.0:

CodePudding user response:

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

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

CodePudding user response:

This solution worked for me react native version 63.3 and gradle 4.2.2

Thank you @Thanhal, I was stuck for 2 days.

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

CodePudding user response:

I'm on 0.64.3 and updading to 0.64.4 and got this error

Task :react-native-locale-detector:compileDebugJavaWithJavac FAILED w: Detected multiple Kotlin daemon sessions at build/kotlin/sessions

any solution? Thanks

  • Related