Reputation: 15413
I just initialized a new React Native project via:
react-native init AwesomeProject
and I am already getting this error:
BUILD FAILED in 3s
error Failed to install the app. Make sure you have an Android emulator running or a device connected. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:installDebug'.
> com.android.builder.testing.api.DeviceException: No connected devices!
* 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 3s
at checkExecSyncError (child_process.js:637:11)
at execFileSync (child_process.js:655:13)
at runOnAllDevices (/Users/danale/Projects/engageMobile/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:75:39)
at buildAndRun (/Users/danale/Projects/engageMobile/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:169:41)
at then.result (/Users/danale/Projects/engageMobile/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/index.js:135:12)
at processTicksAndRejections (internal/process/next_tick.js:81:5)
It is a boilerplate app only thus far. I am using zsh and not bash for command line interface.
I also develop in flutter and I do not get this problem, it opens up the Nexus 5X simulator without a hitch.
What could be the problem?
I tried changing permissions, but that is not it.
Upvotes: 6
Views: 41883
Reputation: 11
For those who are cloning directly from a repo that was in another PC:
Just set permissions to modify in the entire project folder, without it, the system can not use the executables such as: gradlew...
sudo chmod -R 777 ./
(I use this cause' I know the risk, but you can use 644.
Upvotes: 1
Reputation: 450
None of the above worked for me when I start a new project try this
go to android folder and edit build.gradle
set buildToolsVersion = "23.0.1"
mine was 30.0.2 when i changed it to "23.0.1" it started working
In the android folder run
gradlew.bat installDebug
and make sure the Build is successful
That should do it go back to your project folder and run
npm run android
Upvotes: 3
Reputation: 1
Basically open your react native project in android studio, and it will download gradle in android studio instead of the command terminal. then open your command terminal and run the code "npm run android" and it shall work
Upvotes: 0
Reputation: 1
I think you forgot to create virtual device first.
after finish, you can run on cmd/terminal npx react-native run-android
Upvotes: -2
Reputation: 11
I ran across the same problem. Even though my android simulator works fine, once in a while, some corruption occurs, and then react-native run-android throws above error.
One solution that works for me is to close all command prompts, close the virtual devices and re-run them fresh, always worked for me.
Upvotes: 0
Reputation: 15413
So apparently I have more experience with ios
than android
and while react-native run-ios
automatically opens up a simulator for you, react-native run-android
does not, important point, similar commands, don't do similar things, i.e. open up a simulator.
Once I opened up the application inside of Android Studio and then went to AVD Manager and opened up the simulator for Android Studio and then ran react-native run-android
, it worked perfectly.
Upvotes: 5
Reputation: 304
Make sure your Android simulator is running. Close ALL terminal window. Run 'react-native run-android' It's should open two terminal windows. If you see a same error again, close the second terminal ( the one where is compile), and run 'npm start' in 1 open terminal.
Upvotes: 1
Reputation: 400
If your nodejs already running or any device is already connected before init project then it wont be considered for react-native.
Upvotes: 0