react-native: (react-native run-android) -> Error: Command failed: ./gradlew installDebug

I have a problem with runing react-native. When I type react-native run-android it appeare that error !!

Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...

FAILURE: Build failed with an exception.

* What went wrong:
Could not create service of type ScriptPluginFactory using BuildScopeServices.createScriptPluginFactory().
> Could not create service of type PluginResolutionStrategyInternal using BuildScopeServices.createPluginResolutionStrategy().

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html

Command failed: ./gradlew installDebug

Error: Command failed: ./gradlew installDebug
    at checkExecSyncError (child_process.js:601:13)
    at Object.execFileSync (child_process.js:621:13)
    at runOnAllDevices (/home/moun3im/Downloads/AwesomeProject/node_modules/react-native/local-cli/runAndroid/runAndroid.js:299:19)
    at buildAndRun (/home/moun3im/Downloads/AwesomeProject/node_modules/react-native/local-cli/runAndroid/runAndroid.js:135:12)
    at isPackagerRunning.then.result (/home/moun3im/Downloads/AwesomeProject/node_modules/react-native/local-cli/runAndroid/runAndroid.js:65:12)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

This is my react environment

  React Native Environment Info:
    System:
      OS: Linux 4.19 Kali GNU/Linux Rolling 2019.1
      CPU: (4) x64 Intel(R) Core(TM) i5-4200U CPU @ 1.60GHz
      Memory: 116.45 MB / 5.71 GB
      Shell: 5.0.2 - /bin/bash
    Binaries:
      Node: 8.11.2 - /usr/bin/node
      npm: 5.8.0 - /usr/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    npmPackages:
      react: 16.6.3 => 16.6.3 
      react-native: 0.58.3 => 0.58.3 
    npmGlobalPackages:
      react-native-cli: 2.0.1

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 35
  • Comments: 69 (2 by maintainers)

Most upvoted comments

I resolve this pb and it works fine 😃 @mounaim-dev @blackinitial After you create your react native app ,try sudo chmod 777 -R to node-modules and ./android also . -react-native run-android works !

Command failed: ./gradlew installDebug In my case i installed NDK and it solved the problem. Android Studio -> Preferences -> Appearance & Behavior -> System Settings -> Android SDK -> SDK Tools (tab) -> checkbox on NDK -> apply -> OK

Can you run react-native info and edit your issue to include these results under the Environment section?

If you believe this information is irrelevant to the reported issue, you may write [skip envinfo] under Environment to let us know.

sudo react-native run-android Work For me

I resolve this pb and it works fine 😃 @mounaim-dev @blackinitial After you create your react native app ,try sudo chmod 777 -R to node-modules and ./android also . -react-native run-android works !

this not work, still error on command failed ./gradlew installDebug

Solved i downgrade to 0.57.3 and works.

maybe still a bugs in android folder on 0.58.3 version

I fix the problem make downgrade for react native 0.57.3. react-native init --version=“0.57.3” MyNewApp

You must change your build.gradle:

compileSdkVersion 28 buildToolsVersion "28.0.2" minSdkVersion 16 targetSdkVersion 27

and add this line: implementation "com.android.support:appcompat-v7:28.0.0"

facing the same issue:

Command failed: ./gradlew installDebug

Error: Command failed: ./gradlew installDebug
    at checkExecSyncError (child_process.js:618:11)
    at Object.execFileSync (child_process.js:636:13)

I am on latest version of react-native: “0.58.4”

You have to update gradle. These steps are what I did:

  • Open android/build.gradle file and make sure looks like this: dependencies { classpath 'com.android.tools.build:gradle:3.3.1' } … task wrapper(type: Wrapper) { gradleVersion = '4.10' distributionUrl = distributionUrl.replace("bin", "all") }

  • Open android/gradle/wrapper/gradle-wrapper.properties file and make sure looks like this: distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip

@AlexBrasileiro ./gradlew clean and rerun helped me!

Guys, I found a solution for those who need to work with RN in version 0.58.1 (tested on MAC only) Below are the files that I believe needed updating to work.

  1. android/gradle/wrapper/gradle-wrapper.properties
...
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
  1. android/build.gradle
buildscript {
    ext {
        buildToolsVersion = "27.0.3"
        minSdkVersion = 19
        compileSdkVersion = 26
        targetSdkVersion = 26
        supportLibVersion = "26.1.0"
    }
    ...
}
// only as information, it may be that your project does not need or have these items below
allprojects {...}
subprojects {...}
task wrapper(type: Wrapper) {...}

The error: Error: Command failed: ./gradlew installDebug stopped after putting the configurations.all statement below in the file android/app/build.gradle:

  1. android/app/build.gradle
...

android {
    
  compileSdkVersion rootProject.ext.compileSdkVersion
  buildToolsVersion rootProject.ext.buildToolsVersion

  defaultConfig {
      ...
      minSdkVersion rootProject.ext.minSdkVersion
      targetSdkVersion rootProject.ext.targetSdkVersion
      ...
  }
  splits {...}
  buildTypes {...}
  ...

}

// When you put this statement configurations.all, the error has stopped.
configurations.all {
   resolutionStrategy.eachDependency { DependencyResolveDetails details ->
       def requested = details.requested
       if (requested.group == 'com.android.support' && requested.name != 'multidex') {
           details.useVersion "${rootProject.ext.supportLibVersion}"
       }
   }
}

dependencies {
    ...
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"
    ...
}

...

And then, after these settings above:

  • on the root project: cd android && ./gradlew clean
  • on the root project: react-native run-android

Hope it helps someone 😃

I fixed the problem … I just downgraded my java 11 to 8 … that’s all … Thank you so much

Stuck on this issue since entire weekend, I tried downgrading react-native to 0.57.3, it didn’t help. I’m on macOs Mojave, java 8, android studio 3.3.1, followed all instructions given on FB react-native page but no luck, I kept getting op’s error related to gradlew, tried chmod 755 for gradlew and gradlew.bat but in vain. what works however is, if I open my_react_app/android/app in Android Studio then run “react-native run-android” in terminal, I can see app launched.

@b3rday I tried and it doesn’t work … the same issue every time. I think the problem is coming from this file ./gradlew

seems like $JAVA_HOME is different for the gradlew script.

if I echo $JAVA_HOME in the terminal I get : /usr/lib/jvm/java-8-oracle if I echo $JAVA_HOME from inside the script: /usr/lib/jvm/java-8-oracle/jre/bin/java

I will get an output only when using sudo in my case.

Ubuntu 16.04 react-native-cli: 2.0.1 react-native: 0.58.3

@rishiankush Tham

this solution worked for me:

subprojects {
  project.configurations.all {
     resolutionStrategy.eachDependency { details ->
        if (details.requested.group == 'com.android.support'
              && !details.requested.name.contains('multidex') ) {
           details.useVersion "28.0.0"
        }
     }
  }
}

Also I added: maven { url "https://maven.google.com" }

That worked for me too! @rishiankush, you are a fucking God!!!

i slove them by upgrade my project gradle version to 5.2.1. Here is my gradle file : image gradle-wrapper.properties image

I solved this issue by opening the android folder in the android studio. and update the Gradle when Android studio asks you for an update. after update ignores other warnings and error and try again react-native run-android…

I fix the problem make downgrade for react native 0.57.3. react-native init --version=“0.57.3” MyNewApp

this is work for me! !

@rishiankush

this solution worked for me:

subprojects {
  project.configurations.all {
     resolutionStrategy.eachDependency { details ->
        if (details.requested.group == 'com.android.support'
              && !details.requested.name.contains('multidex') ) {
           details.useVersion "28.0.0"
        }
     }
  }
}

Also I added: maven { url "https://maven.google.com" }

Where did you add this?

I myself followed the react native official tutorial step by step

for solving this problem, you can check the main react native repo -> template https://github.com/facebook/react-native/tree/master/template

and after update react native to the last version you must change your build.gradle gradle-wrapper.properties app/build.gradle exactly like the sample project, in blow links:

https://github.com/facebook/react-native/blob/master/template/android/build.gradle

https://github.com/facebook/react-native/blob/master/template/android/gradle/wrapper/gradle-wrapper.properties

https://github.com/facebook/react-native/blob/master/template/android/app/build.gradle

below is my error .emulator in now working but same project work on real device .what can i do dear…

Get more help at https://help.gradle.org

BUILD FAILED in 3s 27 actionable tasks: 1 executed, 26 up-to-date error Could not install the app on the device, read the error above for details. Make sure you have an Android emulator running or a device connected and have set up your Android development environment: https://facebook.github.io/react-native/docs/getting-started.html error Command failed: gradlew.bat app:installDebug. Run CLI with --verbose flag for more details.

Working on Ubuntu 18.04

Downgrade to java 8: sudo update-alternatives --config java Reboot machine

Make sure the .bashrc is configured: sudo nano $HOME/.bashrc

Place in the end of the file: export ANDROID_HOME=$HOME/Android/Sdk export PATH=$PATH:$ANDROID_HOME/tools export PATH=$PATH:$ANDROID_HOME/platform-tools

Usually this happens when the device is not started.

Start your device first (restart it if it was already on).

If that doesn’t work, then proceed to the other recommendations.

this solution worked for me:

subprojects {
  project.configurations.all {
     resolutionStrategy.eachDependency { details ->
        if (details.requested.group == 'com.android.support'
              && !details.requested.name.contains('multidex') ) {
           details.useVersion "28.0.0"
        }
     }
  }
}

Also I added: maven { url "https://maven.google.com" }