Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot run React native app on android device through VS Code

I've created a react-native app in VS Code and trying to run it after settings configuration in launch.json

 "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug Android",
            "program": "${workspaceRoot}/.vscode/launchReactNative.js",
            "type": "reactnative",
            "request": "launch",
            "platform": "android",
            "sourceMaps": true,
            "outDir": "${workspaceRoot}/.vscode/.react"
        }
    ]

I've device connected to the PC and after settings configurations, I pressed F5 but IDE throws error saying

Error while executing command 'react-native.cmd run-android --no-packager' (error code 101)

Please help me to sort this out. Let me know if you need more details about the problem.

like image 363
Sushant Somani Avatar asked Mar 05 '19 05:03

Sushant Somani


People also ask

How do I run React Native run on Android?

Running your React Native application Install the Expo Go app on your iOS or Android phone and connect to the same wireless network as your computer. On Android, use the Expo Go app to scan the QR code from your terminal to open your project. On iOS, use the built-in QR code scanner of the default iOS Camera app.

Can you code React Native in Vscode?

About the extensionThis VS Code extension provides a development environment for React Native projects. Using this extension, you can debug your code and quickly run react-native commands from the command palette.


1 Answers

This error can occur due to several reasons. One of the most common reasons is that your connected device has lost connection. Hence it's important to check that your debug device is still connected.

For this you can use the command:

$ adb devices

Make sure that your device is still connected, and visible. If this is not the case, unplug and replug your device.

If that still did not help, you can follow some additional steps as mentioned in the answers here: how-to-fix-error-device-not-found-with-adb-exe


If your device is however connected, and this error still occurs. Fire up a terminal window in vscode and run the command react-native run-android --no-packager directly.

Here you will now most likely see an error such as Error: Command failed: gradlew.bat installDebug appear. Now slowly scroll up till you reach the *where and *what which should contain more details about what actually is going wrong.

A sample of what this looks like:

* Where:
Build file 'D:\micomputapath\android\app\build.gradle' line: 80

* What went wrong:

A problem occurred evaluating project ':app'.

> Could not read script 'D:\micomputapath\node_modules\react-native-sentry\sentry.gradle' as it does not exist.
like image 144
MX D Avatar answered Oct 09 '22 15:10

MX D