react-native: npx react-native run-android not working
Hi. I am trying to work on an open source project (https://github.com/zulip/zulip-mobile) but when I download the code and run “npx react-native run-android” I get the following error:
FAILURE: Build failed with an exception.
* What went wrong:
Task 'installDebug' not found in project ':app'.
* Try:
Run gradlew tasks to get a list of available tasks. 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 1s
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 app:installDebug. Run CLI with --verbose flag for more details.
I am trying to run on android virtual device. Here is my “npx react-native info” command output:
info
React Native Environment Info:
System:
OS: macOS 10.15.4
CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
Memory: 37.67 MB / 8.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.16.3 - /usr/local/bin/node
Yarn: 1.16.0 - /usr/local/bin/yarn
npm: 6.14.3 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.4, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
IDEs:
Android Studio: 3.6 AI-192.7142.36.36.6308749
Xcode: 11.4/11E146 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.3 => 16.8.3
react-native: 0.59.10 => 0.59.10
npmGlobalPackages:
create-react-native-app: 2.0.2
react-native-cli: 2.0.1
react-native: 0.61.5
Thanks for your help!
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 27 (1 by maintainers)
Hi. I got the same error when I created a blank project with “npx react-native init project” and tried to run it.
Hello, try running
npx react-native doctor
in your project’s directory terminal and when you got the error just press e inside your terminal and it will install/upgrade your files according to itAfter some digging, I found out that the problem must indeed be somewhere in the setup script. This is how I managed to get it up & running (using
npx react-native run-android
). After creating a new project withnpx react-native init AwesomeProject
(as documented in React Native docs), IAwesomeProject\android\app\src\main
AwesomeProject\
:npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-des android/app/src/main/res
AwesomeProject\android\gradle\wrapper\gradle-wrapper.properties
distributionUrl
property into:gradle-6.3-all.zip
AwesomeProject\android\
:gradlew clean
After that I was able to run the project using
npx react-native run-android
without any problems. So to my knowledge, there is a bug somewhere in the setup.Cheers, -P
https://reactnative.dev/docs/environment-setup
Add the following lines to your $HOME/.bash_profile or $HOME/.bashrc (if you are using zsh then ~/.zprofile or ~/.zshrc) config file:
export ANDROID_HOME=$HOME/Library/Android/sdk export PATH=$PATH:$ANDROID_HOME/emulator export PATH=$PATH:$ANDROID_HOME/tools export PATH=$PATH:$ANDROID_HOME/tools/bin export PATH=$PATH:$ANDROID_HOME/platform-tools
Hi @PiPauwels & @mgoral2 Could you run
npx react-native doctor
on your project’s root to identify problems with your environment?@hramos I see that you added “Needs Repro” & “Verify on latest version” ; the steps to reproduce this bug are very simple: follow the setup instructions (on a Windows 10 machine). I tried this multiple times on the current version:
npx react-native init AwesomeProject
cd AwesomeProject
npx react-native start
npx react-native run-android
Result:
Using the steps in my previous comment resolves this issue.
@mgoral2 Did you finally get this to work? I’m having the exact same issue. Strange thing is, opening the project in Android Studio and running it directly from there works just fine, whereas running it from command line doesn’t…
Here is what worked for me: 1.Make sure you turn on Developer mode on your emulator/phone by going to setting->systemInfo->buildNumber Mutiple click on buildnumber to turn on developer mode ( same as real phone) 2. Ad the following the YourProject/android/local.properties Note:if local.properties file is not exist create it by the command “touch YourProject/android/local.properties” sdk.dir = “~/Android/Sdk” 3.Run react-native start 4.Run reac-native run-android Hope it help.
Warning: What I did below is nonsense The problem for me is that I had a faulty build tools so I deleted it and the setup script just downloaded it again and everything worked just fine
Here is what worked for me:
subprojects { afterEvaluate {project -> if (project.hasProperty("android")) { android { compileSdkVersion 28 buildToolsVersion '29.0.0' buildTypes { releaseStaging {} } } } } }
this just change build tools version God knows why I should do that. I’m on Linux btw I don’t know if this will work on Windows or mac.