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

Created on 6 Feb 2019  Â·  69Comments  Â·  Source: facebook/react-native

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
Bug Android Linux Locked

Most helpful comment

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 !

All 69 comments

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.

@react-native-bot i have the same pb during 4 days ,so this my setup for react-native project:

React Native Environment Info:
System:
OS: Linux 4.15 Ubuntu 18.04.1 LTS (Bionic Beaver)
CPU: (4) x64 Intel(R) Core(TM) i5-2520M CPU @ 2.50GHz
Memory: 679.78 MB / 7.68 GB
Shell: 4.4.19 - /bin/bash
Binaries:
Node: 10.15.0 - /usr/local/bin/node
Yarn: 1.13.0 - /usr/bin/yarn
npm: 6.4.1 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
Android SDK:
API Levels: 25, 26, 27, 28
Build Tools: 28.0.3
System Images: android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom, android-28 | Google APIs Intel x86 Atom_64, android-28 | Google Play Intel x86 Atom
IDEs:
Android Studio: 3.3 AI-182.5107.16.33.5199772
npmPackages:
react: 15.4.1 => 15.4.1
react-native: ^0.58.3 => 0.58.3
npmGlobalPackages:
react-native-cli: 2.0.1

same here, i run fresh installation react native but got error

my environtment:

React Native Environment Info:
    System:
      OS: Linux 4.18 Linux Mint 19 (Tara)
      CPU: (2) x64 AMD A9-9400 RADEON R5, 5 COMPUTE CORES 2C+3G
      Memory: 579.45 MB / 3.66 GB
      Shell: 5.4.2 - /usr/bin/zsh
    Binaries:
      Node: 10.5.0 - ~/.nvm/versions/node/v10.5.0/bin/node
      Yarn: 1.12.3 - /usr/bin/yarn
      npm: 6.5.0 - ~/.nvm/versions/node/v10.5.0/bin/npm
    SDKs:
      Android SDK:
        API Levels: 23, 27, 28
        Build Tools: 23.0.1, 27.0.3, 28.0.0
        System Images: android-23 | Intel x86 Atom_64, android-23 | Google APIs Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom
    IDEs:
      Android Studio: 3.1 AI-173.4819257
    npmPackages:
      react: 16.6.3 => 16.6.3 
      react-native: 0.58.3 => 0.58.3 
    npmGlobalPackages:
      react-native-cli: 2.0.1
      react-native-rename: 2.4.0

@blackinitial @mounaim-dev hello guys ! do you resolve the pb :)

@blackinitial @mounaim-dev hello guys ! do you resolve the pb :)

@b3rday No! unfortunately

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

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 !

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

If you look at the error, it states

Could not create service of type ScriptPluginFactory using BuildScopeServices.createScriptPluginFactory().

so probably it's something related to your code. Please provide a repro - without it it's really hard to understand what's going on.

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

@kelset i just run react-native run-android on fresh installation (hello react native)

Solved
i downgrade to 0.57.3 and works.

maybe still a bugs in android folder on 0.58.3 version

just created a new project, and both react-native run-android and ./gradlew installDebug works (macOS)

@dulmandakh the pb is actually with android not macOs :)

@dulmandakh yes, I tried it ... this is happen when I create new project and trying to run it, this error appear and I don't know why .. I tried everything and still not fixed

do you guys use react-native init or some other cli?

I myself followed the react native official tutorial step by step

just replce back slash withe slash in the path
i think in this case the path is 'android/settin.gradle'

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

i upgrade my project to 0.58 and when type react-native run-android
getting error gradlew.bat

Yeah, we are still on JDK 8 (as stated in the docs).

Glad that you found your fix! Closing this

I am having same problem i am using java 7

It is working now after adding android_home environment variable and installing jdk8.

Thank you everyone.

Application is launching on AVD pie 28 but in start it was showing just white blank screen. Now restarting the app it is showing "Welcome to React Native!"

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

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.

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"

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" }

@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 fix the problem make downgrade for react native 0.57.3.
react-native init --version="0.57.3" MyNewApp

this is work for me! !

@Abuitime I added it in android/build.gradle

I also figured out one more thing about this issue:
When we are disconnected with the device.
Then I run adb devices to check I did not found any device connected and after connecting my device, the build was successful

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"

until now there s no solutions provided ?

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

i got the same problem with a fresh installation
React Native Environment Info:
System:
OS: Windows 10
CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Memory: 7.43 GB / 15.88 GB
Binaries:
Yarn: 1.13.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.7.0 - C:\Program Files\nodejs\npm.CMD
IDEs:
Android Studio: Version 3.3.0.0 AI-182.5107.16.33.5264788

@AlaeddineJendoubi
try to do my post, I did it with a fresh installation too

Solution:
Set ANDROID_HOME environment variable with the value pointing towards
C:\Users\<User>\AppData\Local\Android\sdk

Edit:
Also had to cd to C:\Users\<User>\AppData\Local\Android\sdk\tools\android and run
sdkmanager --licenses

Updating gradle using @derast's instructions, accepting license agreements (https://stackoverflow.com/questions/39760172/you-have-not-accepted-the-license-agreements-of-the-following-sdk-components), creating local.properties file in /android with sdk.dir = /Users/USER/Library/Android/sdk, and updating buildToolsVersion to "28.0.3" in build.gradle worked for me 🥵

I implemented Maps in android but it's not working. removing the import Maps from MainApplication.java works for me. Try to remove the import that may cause trouble in your android app.

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

Error: Command failed: ./gradlew installDebug
at checkExecSyncError (child_process.js:616:11)
at Object.execFileSync (child_process.js:634:13)
at runOnAllDevices (/Users/marc/myapp/node_modules/react-native/local-cli/runAndroid/runAndroid.js:299:19)
at buildAndRun (/Users/marc/myapp/node_modules/react-native/local-cli/runAndroid/runAndroid.js:135:12)
at isPackagerRunning.then.result (/Users/marc/myapp/node_modules/react-native/local-cli/runAndroid/runAndroid.js:65:12)
at process._tickCallback (internal/process/next_tick.js:68:7)

➜ myapp git:(master) ✗ react-native info

React Native Environment Info:
System:
OS: macOS 10.14.3
CPU: (4) x64 Intel(R) Core(TM) i5-5250U CPU @ 1.60GHz
Memory: 78.71 MB / 8.00 GB
Shell: 5.3 - /bin/zsh
Binaries:
Node: 10.15.1 - /usr/local/bin/node
Yarn: 1.13.0 - /usr/local/bin/yarn
npm: 6.4.1 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
Android SDK:
API Levels: 28
Build Tools: 28.0.3
System Images: android-28 | Intel x86 Atom_64
IDEs:
Android Studio: 3.3 AI-182.5107.16.33.5264788
Xcode: 10.1/10B61 - /usr/bin/xcodebuild
npmPackages:
react: 16.6.3 => 16.6.3
react-native: 0.58.5 => 0.58.5
npmGlobalPackages:
react-native-cli: 2.0.1

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

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.

Command failed: gradlew.bat app:installDebug.

how do chmod on windows?

Apparently, there's no equivalent.

I installed "github bash"... Made my life so much easier.

Same error:

BUILD FAILED in 2s
10 actionable tasks: 1 executed, 9 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.

I countered similar error. My solutions is make sure your devices is authorized, run adb devices in your terminal to see your listed devices/emulators and make sure it doesn't says "unauthorized". If it says unauthorized, make sure your phone is in USB Debugging Mode.

Try restart adb after the changes by using adb kill-server and adb start-server commands. I hope it can help you. Good Luck

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

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

I fixed this issue by uninstalling java 11 and making sure java 8 was installed.

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.

sudo react-native run-android
Work For me

Solved
i downgrade to 0.57.3 and works.

maybe still a bugs in android folder on 0.58.3 version

How to downgrade?

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

2) 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:

3) 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 :)

@AlexBrasileiro ./gradlew clean and rerun helped me!

@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 fix the problem make downgrade for react native 0.57.3.
react-native init --version="0.57.3" MyNewApp

this is work for me! !

Yes this also worked for me

I got the same issues when using Genymotion for virtual devices.
Then go to Settings of Genymotion -> ADB -> Use custom Android SDK tools -> react-native run-android again -> It worked for me.

Hope this help.

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

I just solved this problem after several days of trying to get this to work and it was because my android device for running the app was not connected properly and wasn't seen. These are the steps i took to resolve the issue
After creating my project using react-native init projectName, i had to check first if my android device is seen and connected using adb devices as i'm not using an emulator and i got this message, which by interpretation means my device is seen and connected

List of devices attached
0257718001100008        device

If your device is not connected and you run adb devices, you will not get this output 0257718001100008 device which means your device is not connected. Make sure you have a connected device before running react-native run-android

My packages and versions
react-native-cli: 2.0.1
react-native: 0.59.9
node v12.3.1
npm 6.9.0
yarn 1.16.0

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

I am also facing this problem., How can I fix it? can you explain it?

image

hello i also have a problem
reactBug

Please, try to:

  1. Import your project on Android Studio myproject/android
    OBS: It has to be on /android root folder, so Android Studio will build
    your application.

  2. Make sure build is OK.

  3. Click at Run button and select your Android device as target.
    You will receive a red screen error, don't get in panic!

  4. Run react react-native start on your project root folder /yourproject

  5. Open another tab and Run react-native run-android.

Did it work for you?

On Mon, 22 Jul 2019 at 21:20, Jessy-warom notifications@github.com wrote:

hello i also have a problem
[image: reactBug]
https://user-images.githubusercontent.com/53199688/61673470-9b8cc080-acbd-11e9-9e2c-0006116c2e44.png

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/facebook/react-native/issues/23306?email_source=notifications&email_token=AESMQT36IE6EXXYKHEZUWGDQAZFE5A5CNFSM4GUTOP6KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2RQ5WI#issuecomment-514002649,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AESMQT2NJHKEVCHVTZ3KXU3QAZFE5ANCNFSM4GUTOP6A
.

for problem resolved try react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res in followed react-native run-android

sudo react-native run-android
Work For me

It works!

every time I run react-native, I get an error. Failed to launch the emulator. Reason: No emulator was found as output from emulator -list-avds.
does anyone know why that could happen?

fixed the error by removing other projects to another folder

Try the following command, it works for me 'Mac-Linux': sudo react-native run-android

Was this page helpful?
0 / 5 - 0 ratings