React-native project error "could not connect to development server" - android

When I run "react-native run-android", it gives me the error:
could not connect to development server...
So I had to start my project as follows:
Going to the android folder running ./gradlew clean
In root folder react-native run-android.
Only after that the project run's.
I have to repeat this cycle every time I run my project.
Is there any permanent solution to get rid of this?

Quicker solution: run npm start when you get error could not connect to development server... happens.
A permanent solution may require you to reinstall or update most of your dev tools.

Related

How to fix "Error spawn Unknown system error -8" in react native

I have that weird error when running "npx react-native run-android" that is only occuring in a specific react native project only on my Macbook with android simulator. Other RN apps are running fine on my mac with android.
On a windows pc this specific RN app is also working fine.
Error: spawn Unknown system error -8
at ChildProcess.spawn (node:internal/child_process:413:11)
at Object.spawn (node:child_process:743:9)
at module.exports (/Users/hannes/Projects/test2/mapp/native-frame/node_modules/#react-native-community/cli-platform-android/node_modules/execa/index.js:205:26)
I tried the following things:
deleting package-lock.json
rm -r node_modules + gradlew clean (in android folder)
creating a new virtual device in android studio with API level according to build.gradle
upgrading node to 18.8.0
upgrading npm to 8.18.0
npm cache clean –force
Somebody any ideas?
After using "run-ios" in the meantime I had to face the problem again and found a solution.
npx react-native run-android
this line is using the port 8081 and my macbook did sometimes use this port for another service
lsof -i tcp:8081
this command showed the process that was running
COMMAND PID FD DEVICE SIZE/OFF NODE NAME
node 44492 24u 0t0 TCP *:sunproxyadmin (LISTEN)
I terminated this process but still got the error message.
So I called the gradle command for building and installing the app myself.
cd android && ./gradlew app:installDebug -PreactNativeDevServerPort=8081
This worked, the app got build and installed on my android device but I got multiple error messages in the android studio run console starting with:
Could not find generated setter for class
this error was also addressed on GitHub and Stackoverflow
So building and installing the app in production mode solved the problem for me.
./gradlew app:installRelease

React Native response error 500

enter image description here]1
I am doing following step to start react application
react-native init reactTutorialApp
react-native run-android
by followed these steps and it is installing on Device successfully. but i am getting a following error.
The development server return response error code:500
PFA
I think you forgot to run one command, the one to start the development server.
Try:
react-native init reactTutorialApp
run the following command in the project root folder, but in another tab (this process need to be running when you're developing:
react-native start
And now you can run: react-native run-android
Tell me if it solve your problem.

Unable to connect development server. Ensure that the packager server is running

I am a starter of React-native tho I am having trouble with debugging. Program is successfully installing apk to emulator but can not render the component. Whenever I double press 'R' (I am on windows) it throws following error
Try:
cd YourProject
react-native run-android
react-native start

Native-starter-kit won't run properly

I'm talking about this starter kit here
What I have done:
Clone the repo to a local folder
cd into the folder, run npm install
Run react-native link
Run react-native run-android
Run react-native run-android again
What I got:
Error from React Packager
Looking for JS files in
D:\Projects\ReactNative\native-starter-kit
Loading dependency graph...
React packager ready.
Loading dependency graph, done.
Bundling `index.android.js` 100.0% (974/974), done.
ERROR EPERM: operation not permitted, lstat 'D:\Projects\ReactNative\native-starter-kit\android\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml'
{"errno":-4048,"code":"EPERM","syscall":"lstat","path":"D:\\Projects\\ReactNative\\native-starter-kit\\android\\app\\build\\intermediates\\incremental\\mergeDebugResources\\merged.dir\\values\\values.xml"}
Error: EPERM: operation not permitted, lstat 'D:\Projects\ReactNative\native-starter-kit\android\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml'
at Error (native)
See http://facebook.github.io/react-native/docs/troubleshooting.html
for common problems and solutions.
Press any key to continue . . .
I can't get the sample project deployed properly on my device. Notice that I run react-native run-android twice.
The first time, the bundling finished, but my device only show white background with nothing whatsoever. Then I try to run it again.
The second, the react packager got an error.
Any idea about this?
Change directory to Android folder of your project:
cd /path/to/project/android
gradlew clean
react-native run-android again.

ReactNative build for android just freezes over the last step

I was developing a React Native project as always; when I encountered the following error after doing react-native run android or equivalently cd android && ./gradlew installDebug.
It's just over the last step that this exception is caught:`
:app:assembleDebug
:app:installDebug
Exception in thread "Device List Monitor" java.lang.NullPointerException
at com.android.ddmlib.EmulatorConsole.checkConnection(EmulatorConsole.java:317)
at com.android.ddmlib.EmulatorConsole.getConsole(EmulatorConsole.java:231)
at com.android.ddmlib.DeviceMonitor.queryAvdName(DeviceMonitor.java:248)
at com.android.ddmlib.DeviceMonitor.updateDevices(DeviceMonitor.java:220)
at com.android.ddmlib.DeviceMonitor.access$400(DeviceMonitor.java:65)
at com.android.ddmlib.DeviceMonitor$DeviceListUpdateListener.deviceListUpdate(DeviceMonitor.java:662)
at com.android.ddmlib.DeviceMonitor$DeviceListMonitorTask.processIncomingDeviceData(DeviceMonitor.java:847)
at com.android.ddmlib.DeviceMonitor$DeviceListMonitorTask.run(DeviceMonitor.java:781)
at java.lang.Thread.run(Thread.java:745)
> Building 97% > :app:installDebug`
I'm coding on react-native version 0.43.2 and react-native-cli 2.0.1, also npm 4.1.2 and yarn 0.21.3; Ubuntu 16.04. So everything is armed to teeth by the latest version but I still can't figure out the problem. It happens even for a project I just create by react-native init, it's every where. :(
P.S. be sure my emulator is up and running and the problem isn't due to it.
Try restarting adb in to make it probe the local 5554 port
killall adb; adb devices
Actually, I never found the reason or the solution to the problem. But what I know, I went on with my daily work, and after a day or two (with a couple of restarts in this period) it began working again. And till now, I haven't encountered the problem again.
try to specify the path for sdk/build-tools in the terminal
export PATH="Users/YOURUSERNAME/Library/Android/sdk/build-tools/...":$PATH
after that restart the emulator and try
npm run android
The fix I have found that works for me is to:
Close the emulated device so you have nothing listed when running adb devices
Run react-native run-android so the build fails correctly with a No connected devices! error
Restart the emulator and run react-native run-android again
Unfortunately I still have to run this after every restart, would love to get to the root cause and fix it once and for all!
If you had hit the following error while installing watchman, you will most likely hit the issue mentioned in this discussion
Warning: The post-install step did not complete successfully
If this is the case, check what the watchman window shows. If it is something like this:
Watchman: watchman --no-pretty get-sockname returned with exit code=1, signal=null, stderr= 2018-08-24T17:37:44,142: [0x7fffab20d380] while computing sockname: failed to create /usr/local/var/run/watchman/macbookpro-state: No such file or directory
Do
> brew uninstall watchman
> cd /usr/local/var/
> sudo chown -R $(whoami) var
> brew update
> brew install watchman
Kill/close the emulator device and run the command
> react-native run-android
You should see the action fail with message like
> com.android.builder.testing.api.DeviceException: No connected devices!
Now, rerun the command to see the compilation successful and the app opening up in the emulator
> react-native run-android

Categories

Resources