Home > OS >  Android Build Failure: Common Issue- Failed to install the app. Error: Command failed: ./gradlew app
Android Build Failure: Common Issue- Failed to install the app. Error: Command failed: ./gradlew app

Time:11-07

React Native Android build failure without any changes due to publish of React Native version 0.71.0-rc.0

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:

There will be build failures for Android due to the publish of the React Native version 0.71.0-rc0.

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

Ref: Fix and updates on Android build failures happening since Nov 4th 2022 #35210

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: https://github.com/facebook/react-native/issues/35210#issuecomment-1304536693

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