React native Cannot connect to react-devtools using android simulator - android

I execute the project with react-native run-android and in another terminal, i do:
npm run react-devtools
and it opens the new window of electron that says:
The react native app it will open in a few seconds...
but nothing happens.
I put in the simulator toggle inspector with Ctrl + m and i can see in networks that it makes a request to http://localhost:8097 and the result is it fails to connect and keeps trying with the same result.
The window of electron that is open it says that it wait connections to the port 8097 so i can see is trying to connect but with no results!

You need to run this command in a new terminal adb reverse tcp:8097 tcp:8097

react-devtools v4 is incompatible with react-native
try version 3 instead of version 4:
npm install -d -g react-devtools#3.x, it's worked for me.

The answer by #Unemployed3494 didn't work for me. Instead I killed all running processes belonging to my Mac OS user with this command:
pkill -u username
After doing so, react devtools connected as expected to the simulator.

Related

React Native app: cannot connect to dev server, but the simulator is running - why?

The image describes my current situation properly. Please have a look at it first.
I am running my app on React Native. I have Android simulator on. I give the command to start the app. The app build finishes, but it says that virtual device not found, and in my simulator, if I open the app manually, it says that it cannot connect to Development server. It shows some issues.
Can anyone help?
Try run react-native run-android to connect your app to the emulator
Check USB Debugging is on(mostly running on virtual devices)
Check how you created project(react-native-cli or Expo) and run relevant app run command
Make sure your development server(node.js) is running when you run app. Sometimes it crashes then you have to again run command to run app
If all the step does not solve your issue try to uninstall app from device and run app again. Since react-native is still developing and its wired sometime these tricks works
I was having the same issue in Ubuntu 16.04. In my case the problem was that node packager wasn't running.
To check is packager is running easily you can open the browser and enter
http://localhost:8081/
You must see "React Native packager is running."
If you dont, then you can start packager from console running
react-native start
If you get an error like
" ERROR watch /your/project/path/android/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values-ru ENOSPC"
Then run first
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Then run react-native start again and press the letter R twice in the emulator to reload.
Looking at the screenshot, seems like you don't have adb installed because there is a clear 'adb: not found error'.
Luckily Android studio ships with adb and is present in platform-tools under your Android SDK. (generally in /home/your-user-name/Android/Sdk/)
You only need to use it. Create a symbolic link in '/usr/bin/' or '/usr/local/bin/' depending how you'd like to use it.
Run the command:
sudo ln -s ~/Android/Sdk/platform-tools/adb /usr/local/bin/
After this run the app.

Unable to connect with remote debugger

I'm using React.JS and when I do react-native run-android (with my device plugged in) I see a blank page. When I shake the device and select Debug JS Remotely from the option list I see the following screen.
FYI:
OS: Ubuntu 16.04
Node version is: v4.6.2
java version "1.8.0_111"
react": "15.4.1
react-native": "0.38.0
In my case the issue was that the emulator was making a request to:
http://10.0.2.2:8081/debugger-ui
instead of:
http://localhost:8081/debugger-ui and the request was failing.
To solve the issue: Before enabling remote debugging on your emulator, open http://localhost:8081/debugger-ui in chrome. Then enable remote debugging and go back to the chrome page where you should see your console logs.
Solved the issue following:
Press Cmd + M on emulator screen
Go to Dev settings > Debug server host & port for device
Set localhost:8081
Rerun the android app: react-native run-android
Debugger is connected now!
I solved it doing adb reverse tcp:8081 tcp:8081 and then reload on my phone.
In my case, selecting Debug JS Remotely launched Chrome, but did not connect with the android device. Normally, the new Chrome tab/window would have the debugging URL pre-populated in the address bar, but in this case the address bar was blank. After the timeout period, the "Unable to connect with remote debugger" error message was displayed. I fixed this with the following procedure:
Run adb reverse tcp:8081 tcp:8081
Paste http://localhost:8081/debugger-ui into the address field of my Chrome browser. You should see the normal debugging screen but your app will still not be connected.
That should fix the problem. If not, you may need to take the following additional steps:
Close and uninstall the app from your Android device
Reinstall the app with react-native run-android
Enable remote debugging on your app.
Your app should now be connected to the debugger.
I had a similar issue that led me to this question. In my browser debugger I was getting this error message:
Access to fetch at 'http://localhost:8081/index.delta?platform=android&dev=true&minify=false' from origin 'http://127.0.0.1:8081' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
It took me awhile to realize I was using 127.0.0.1:8081 instead of localhost:8081 for my debugger.
To fix it, I simply had to change Chrome from:
http://127.0.0.1:8081/debugger-ui/
to
http://localhost:8081/debugger-ui/
My case is that when I tap enable remote JS debugging, it will launch chrome, but can not connect to it.
I have tried to run:
adb reverse tcp:8081 tcp:8081
, did but not work.
I uninstalled my chrome totally and install a new one. And it works.
The other answers here were missing one crucial step for me. In AndroidManifest.xml I needed to add usesCleartextTraffic:
<application
...
android:usesCleartextTraffic="true">
You probably don't want to keep this in the production release of your app though, unless you want to support insecure http requests.
After I added this to my AndroidManifest.xml, then I followed Tom Aranda's answer, and the emulator was finally able to connect to the debugger.
Make sure that the node server to provide the bundle is running in the background. To run start the server use npm start or react-native start and keep the tab open during development
react-native start --reset-cache in one tab and react-native run-android in another
adb reverse tcp:8081 tcp:8081 ( so you could add it to your scripts and just run yarn run adb-reverse)
If you're using android, Instead of shake your phone a great tip is run adb commands.
So you can run:
adb shell input keyevent 82 (menu option )
adb shell input keyevent 46 46 ( reload )
I did #sajib s answer and used this script to redirect ports:
#!/usr/bin/env bash
# packager
adb reverse tcp:8081 tcp:8081
adb -d reverse tcp:8081 tcp:8081
adb -e reverse tcp:8081 tcp:8081
echo "🚧 React Native Packager Redirected 🚧"
uninstall your application, then run react-native run-android. then click debugging end in chrome replace http://localhost:8081/debugger-ui/, end run react-native run-android. if you still haven't succeeded try again
Inculding all impressive answers the expert developers specially Ribamar Santos provided, if you didn't get it working, you must check something more tricky!
Something like Airplane mode of your (emulated) phone! Or your network status of Emulator (Data status and Voice status on Cellular tab of Emulator configuration) that might be manipulated to don't express network! for some emulation needs!
I've overcome to this problem by this trick! It was a bit breathtaking debug to find this hole!
in my case it also need to install it's npm package
so
npm install react-native-debugger -g
Try adding this
package.json
devDependencies: {
//...
"#react-native-community/cli-debugger-ui": "4.7.0"
}
Terminate everything.
npm install
npx react-native start
npx react-native run-android
Reference: https://github.com/react-native-community/cli/issues/1081#issuecomment-614223917
Trouble shooting React native with React Cli and Typescript/js (Android Emulator)
Check if 'android/src/mai/assets/index.android.bundle' is available. If no Create index.android.bundle file in 'android/src/main/assets'
If above path not available then create the path then file
3.Run for bundling : 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
4.a. By default development server runs on 8081 port. Run 'react-native start' then on browser check if 'http://localhost:8081' and 'http://yourIP:8081' works. If yes then
Open application in Android Emulator (react-native run-android)
Click Ctrl + M
Select Settings
Select Debug Server Host and Port For Device
Add 'YourIPAddress:8081' e.g. 10.0.2.2:8081
4.b If http://localhost:8081 not working then run react-native port=8088(or any port)once successfully executed. Check on browser http://localhost:8088 and http://yourIP:8088 works. Yes then Open application in Android Emulator (react-native run-android)
Click 'Ctrl + M'
Select Settings-
Select Debug Server Host and Port For Device-
Add 'YourIPAddress:8081' e.g. 10.0.2.2:8088
YourIPAddress : Open command promt -> write 'ipconfig' -> copy IPv4 address
As for my own case , i was using the expo go and my android phone for my emulator and it was giving me this error.
so what i did was to clear the expo go app cache & data on my android device. it was working just fine
TL;DR:
If you created the app with expo cli with some native code or libraries not supported by expo, try this command in case the other solutions do not work.
npx expo run:android
Docs
My scenario:
I tried to run one of my old expo applications by building the app from Android studio and faced this issue. The other solutions mentioned didn't work. When I tried to use Expo Go to scan the QR, I got to know the error. Since I had used react-native-mmkv, I couldn't use expo-cli, I had to eject. So I ran npx expo run:android and everything started working fine.
The solution is to clear the expo go application data to solve the problem. Ref to: How to disable Remote JS Debugging in React-Native

react-native run-android: usb debugging not working

I have installed the development environment for react native on Windows 7 using the instructions here.
I have installed the following packages:
Python 2.7
node 4.2.4
npm 2.14.12
react-native-cli 0.1.10
react-native 0.18.0-rc
Android SDK
I can generate a skeleton project using the command react-native init Test.
However, when I execute the command react-native run-android, the following error occurs: Unable to install path\to\app-debug.apk.
The device, a Samsung Galuxy running Android 5.0.1, is connected to my PC and USB debugging on the phone has been enabled. When I type adb devices the phone appears in the list.
I can download the apk to the phone manually using the command adb install. However, when I run the app, a red screen appears with the error "Unable to download js bundle." This error persists even after I do the following:
Start the local development server using react-native start
Executing the command: adb reverse tcp:8081 tcp:8081
On the phone, setting the debug server host and port to localhost:8081
Update: I have solved one problem by downloading gradle to version 1.2.3 as described here. However, the red screen still appears with the error Unable to download js bundle.
What could be the problem?
You are working fine. for this problem have added the IP address in device Setting server host. one more thing your machine and device should have on same network.

error "Could not get BatchedBridge, make sure your bundle is packaged properly" on start of app

Trying to create a react-native project on Android 4.4.2 I get this error screen
and couldn't find any way to resolve it. I tried restarting packager, reconnecting device, even reinstalling react native and starting new project. On 6.0.0 and later versions it works just fine.
A possible solution for this is that you most probably not bundling your application first, perform the following steps and then deploy your app-debug.apk to your device
$ cd myproject
$ react-native start > /dev/null 2>&1 &
$ curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
(if the folder assets does not exists create it)
Then run from project root
$> (cd android/ && ./gradlew assembleDebug)
install the created apk to you device, from location: android/app/build/outputs/apk/app-debug.apk
let me know if that fixes your issue
EDIT:
You can simply put it to your package.json as a script to automate it, I believe it will be fixed in upcoming releases of react-native and will be executed prior assembling the final APK, hence this won't be needed (I hope as well)
put :
"scripts": {
"build": "(cd android/ && ./gradlew assembleDebug)",
"start": "node node_modules/react-native/local-cli/cli.js start",
"bundle-android": "react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --sourcemap-output android/app/src/main/assets/index.android.map --assets-dest android/app/src/main/res/"
},
or as mentioned the curl equivalent, but for most cases the above is more robust
I came across this issue as well.
What I did was force kill the app on my device, then I opened up another console and ran
react-native start
and then I opened the app again from my device and it started working again.
EDIT: If you are using an android device via USB and have unplugged it or your computer went to sleep, you may have to first run
adb reverse tcp:8081 tcp:8081
Just got this error. Here's what I did to fix:
I selected Dismiss, Went into the Developer menu, then Dev Settings,
Choose Debug server host & port for device, I added my computers IP address and the port: 192.168.0.xx:8xxx, use whatever your developer machines assigned IP address is on your wifi network. The port is usually :8081
Once I did this, all went well. Also, while you're in the dev menu remember to select Enable Live Reload and Debug JS Remotely, it makes your life much-much easier while debugging.
This is what worked for me (After trying every other solution i found ...):
Run adb reverse tcp:8081 tcp:8081 inside \Android\sdk\platform-tools
I got this also when I started for the first time with React Native, using a physical device. If that's the case, you need to do some extra things before you can get started. You have to enter some information about your development machine in the 'Dev Settings' of React Native.
When you see the error, shake your device. A dialog will popup, the last option will be 'Dev Settings'. Select 'Debug server hot & port for device' and enter your local IP and the used port (usually 8081).
See the last paragraph of https://facebook.github.io/react-native/docs/running-on-device-android.html
If none of the solution work for you try this:
I found that my <root>/android/app/build/intermediates/assets/debug folder was empty and by running cd android && ./gradlew assembleDebug was not creating those files required, which are later used by javascript thread in our react native apps.
I ran manually the following command which the debug build command should have created ideally.
node node_modules/react-native/local-cli/cli.js bundle --platform android --dev true --reset-cache --entry-file index.android.js --bundle-output /<path to dir>/android/app/build/intermediates/assets/debug/index.android.bundle --assets-dest /<path to dir>/android/app/build/intermediates/res/merged/debug
After running these commands I found two bundle files in this directory <root>/android/app/build/intermediates/assets/debug
And then a I ran again cd android && ./gradlew installDebug my app started working again.
Will debug more and would update what is failing actually.
In a separate terminal, connect your device to the computer and run the following commands:
react-native start
cd user/Library/Android/sdk/platform-tools/
./adb reverse tcp:8081 tcp:8081
Application terminal:
react-native run-android
install apk on your device from this location android/app/build/outputs/apk/app-debug.apk
It's little too late but this really works for me.
react-native run-android.
react-native start.
First command will build apk for android and deploy it on your device if its connected. When you open the App it will show red screen with error. Then run second command which will run packager and build app bundle for you.
see issue:
1.react-native start
2.click Reload(R,R) on your device.
Try this command in terminal and then reload. It worked for me
adb reverse tcp:8081 tcp:8081
restart the genymotion
run react-native run-android
the problem was solved
I was having the same exception on the device Z3 Compact D5803 - 6.0.1
I went opened the .buckconfig file and changed the line:
target = Google Inc.:Google APIs:23
to
target = Google Inc.:Google APIs:24
Because i saw in SDK Manager that Android 6.X has api level 24.
For me, it's because adb was not in the PATH. It's located /Users/man/Library/Android/sdk/platform-tools for me, it may be somewhere else for you, but anyway, find it and add it to your path to see if that help.
Since you are using Android < 5.0 you can't use the default adb reverse method, but Facebook has added official documentation to connect to the development server via Wi-Fi, which would support your version. Quoting the instructions for MacOS, but they also have them for Linux and Windows:
Method 2: Connect via Wi-Fi
You can also connect to the development server over Wi-Fi. You'll first need to install the app on your device using a USB cable, but once that has been done you can debug wirelessly by following these instructions. You'll need your development machine's current IP address before proceeding.
You can find the IP address in System Preferences → Network.
Make sure your laptop and your phone are on the same Wi-Fi network.
Open your React Native app on your device.
You'll see a red screen with an error. This is OK. The following steps will fix that.
Open the in-app Developer menu.
Go to Dev Settings → Debug server host for device.
Type in your machine's IP address and the port of the local dev server (e.g. 10.0.1.1:8081).
Go back to the Developer menu and select Reload JS.
It had this issue "randomly" and took me sometime to realize what was wrong in my scenario.
After I have updated to React-native-cli 2.0.1, there was a message output to the log which helped me to dig and find the root cause:
JS server not recognized, continuing with build...
After researching some links I found this one:
Unable to recognize JS server
Since I´m on windows, I ran netstat and found out that my VLC player was also running on port 8081 causing the issue.
So, in my case, if I started the vlc server prior to the react-native server it wouldn´t work.
This same log message wasn´t output on previous versions of the react-native-cli, making it fail silently.
TL, DR: check if there´s anything running on the same port as the package manager (8081 by default)
someone suggested the following one
react-native run-android
react-native start --reset-cache,
But in my case, I just close the cli command prompt window and used the following.
npx react-native run-android
and it worked fine.
My way are:
react-native start
After that in your device using:
click to Reload.
See in console react-native, it will be fetch js bundle data.
My issue was that I went through my AndroidManifest.xml file and had removed the line
<uses-permission android:name="android.permission.INTERNET" />
because my app will not need internet. However, the react native debugging app does need internet access (to access the packager) Whoops. :)
I had the same problem. When I did create a react native project via create-react-native-app AwesomeProject it worked well in Expo app on phone. After that I wanted to use that quickstart project for developing my project and got same error as you do.
After some research I find out it's better to start new project with react-native init AwesomeProject (with all setting in react native docs) Then run this command:
react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
That should fix the thing with bundle (--dev false is not showing warnings)
All you need to do for app to run on your virtual / real device is:
react-native run-android
And it should be working just fine. At least it worked for me.
Try to clean cache
react-native start --reset-cache
Please check if you have following error when you run react-native run-android:
adb server version (XX) doesn't match this client (XX); killing...
In that case make sure /usr/local/opt/android-sdk/platform-tools/adb and /usr/local/bin/adb are pointed to the same adb
In my case one was pointed to /Users/sd/Library/Android/sdk/platform-tools/adb (Android SDK), but another was pointed to /usr/local/Caskroom/android-platform-tools/26.0.2/platform-tools/adb (Homebrew)
And issue have been fixed after both of them pointed to /Users/sd/Library/Android/sdk/platform-tools/adb (Android SDK)
I got this error too, really confused. cuz all answers does not work.
Just after add adb to path.
For me, I had side-sync enabled and active. Closing it imediately made the issue go away. It might be worth closing this or any other communication between PC and device
I ended up having to open up the port that I was using (8081 by default). On Linux, you can do the following
sudo iptables -A INPUT -p tcp --dport 8081 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -p tcp --sport 8081 -m conntrack --ctstate ESTABLISHED -j ACCEPT
You can test to see whether you actually need to do this. Just navigate to your dev server in Chrome on your Android device. If it doesn't respond, then this might be what you need. If it does respond, then this won't help you.
For me the problem was that 'adb' was not recognised - check this answer.
To fix this add C:\Users\USERNAME\AppData\Local\Android\sdk\platform-tools to Environment Variables
Most of us face this problem for the first time, when we start react native project#1.
Few simple steps solved my problem:
I created a sample project using command:
react-native init ReactProject1
Solution
The fix is to help local-cli\runAndroid\adb.js to find adb.exe, the same way as local-cli\runAndroid\runAndroid.js:
find replace statement under projectname(whatever you have given)\node_modules\react-native\local-cli\runAndroid
Replace:
const devicesResult = child_process.execSync('adb devices');
By:
const devicesResult = child_process.execSync( (process.env.ANDROID_HOME ? process.env.ANDROID_HOME + '/platform-tools/' : '') + 'adb devices');
after doing above replacement, just run react-native run-android in your cmd, it will bundle apk and at first try to install js bundle locally in your device. (Got Success)
"npm start"
I just closed the terminal and open a new one. Went to project location by cd command. And then just simply type - "npm start". and then 'r' for reload. Everything just vanished. I think everybody should try this at once.
I tried many of the suggestions above/below, but ultimately, the issue I faced was a permissions one with watchman, which was installed using homebrew earlier. If you look at your terminal messages while trying to use the emulator, and encounter 'Permission denied' errors with regards to watchman along with this 'Could not get BatchedBridge" message on your emulator, do the following:
Go to your /Users/<username>/Library/LaunchAgents directory and change the permissions settings so your user can Read and Write. This is regardless of whether or not you actually have a com.github.facebook.watchman.plist file in there.
I found that I needed to also add in a
react-native upgrade
to get the application to run correctly.
I got the same issue but it was a stupid mistake from myself...
From Android studio, I was launching installDebug/installRelease gradle script from app projet instead of root projet.

React Native 'hello world' quick start: "could not connect to development server"

I'm trying to do the react native 'hello world', and I'm using usb debugging on my android.
I ran react-native run-android, then react-native start.
I can view the js file in localhost, but get 'could not connect to development server' message on my phone.
I followed the instructions to run adb reverse tcp:8081 tcp:8081, then realized that command doesn't exist, so I ran adb forward tcp:8081 tcp:8081 instead.
Still no luck. Using react-native#0.22.0, ubuntu 14.04. My phone is nexus 5 on android 6.0.1.
How can I allow my phone to access my localhost?
By the way, it is working over wifi, but I'd like to get it working over usb.
Just another scenario, this error happened to me when I forgot to run react-native start command. I usually follow the steps here when I start new project. The steps in a nutshell are as follows (Android in my case):
Start Android Studio -> AVD Manager -> select your aVD and click Start from action
inside the directory where you want to create your new project, open your command line and run:
$ react-native init <Your new project name/it is also the registration name>
$ cd <the new directory you created>
$ react-native start //This is the step that I forgot
Open a new command prompt and run the following inside the same directory(you just created) to launch the app on your AVD.
$ react-native run-android
If everything is set up correctly, you should see your new app running in your Android emulator shortly.
You'll find in the file index.android.js in the home directory of your project, the last line contians the App registry using the same name you used in the first command above
adb reverse tcp:8081 tcp:8081 Only works for android 5.0 + for running app on devices with android versions lesser than 5.0 hit following command after npm start is done in Terminal (in app directory folder).
curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
now run the app, it will work. Only drawback is that every time you make a change you need to fire the command again and run the app again.
I found the solution :)
I am on ubuntu 16, so, I used command ip addr show which gave me my computer ip address.
I used this ip address and I was able to access localhost on my mobile.
Finally I added the ip address and port no to devsettings of android phone and My app was able to access development server
10 mins ago I had the same problem I guess, and the way I solved this was reading this
https://facebook.github.io/react-native/docs/running-on-device-android.html
and when I did that, I found that I didn't have android-tools-adb installed,
so looking around I found
'No command 'adb' found' error on Ubuntu
which gives me the answer
sudo apt-get install android-tools-adb
and after all this I set
export PATH=${PATH}:~/android-sdk-linux/tools
export PATH=${PATH}:~/android-sdk-linux/platform-tools
then everything works fine, now I can see my app in my Android device.
BTW the option I choose from react native docs was the one that says me
"Using adb reverse
Note that this option is available on devices running Android 5.0+ (API 21).
Have your device connected via USB with debugging enabled (see paragraph above on how to enable USB debugging on your device).
Run adb reverse tcp:8081 tcp:8081
You can use Reload JS and other development options with no extra configuration
I am having seen the same issue, and that's all because the android app don't have this permission:
<uses-permission android:name="android.permission.INTERNET" />
I had a similar problem. I would get this error when trying to get it to run on device. It was working fine on my simulators on my computer.
The problem was when I would do adb devices or react-native run-android I would get "ADB is Not Recognized as an internal or external command".
So my fix was to add the path to adb.exe's parent directory to my Environment Variables and then restart my command prompts. After I did that, adb devices would not throw the "unrecognized internal external blah" and it listed my device. I then ran react-native run-android and on startup no more red screen showing the completely useless error message Error calling AppRegistry.runApplication! :)
So I found ADB was located in my folder:
C:\Users\dell\AppData\Local\Android\sdk\platform-tools\adb.exe
I am on a Windows 10 system. dell is my user name of the computer.
So I went to System Environemnt Variables then found "Path" then clicked "Edit", then clicked "New" and added in "C:\Users\dell\AppData\Local\Android\sdk\platform-tools".

Categories

Resources