I'm trying to run an app inside my Android emulator and on my Iphone using Expo and Create React Native App.
I' ve ran the following commands to do this.
create-react-native-app MyFirstApp
npm run android
After doing the run command the app runs in the emulator with the following error:
Something went wrong! Could not load *ip*. Network response timed out.
Uncaught error: java.net.SocketTimeoutException: connect timed out.
The same thing happens when I scan the QR code on my Iphone and I can't reach the ip in my web browser.
I've found the following fixes on internet but nothing seems to work:
Add port 19000 to the inbound rules in Windows Firewall
Update Java and npm
npm start instead of npm run android
Edit:
I installed Expo XDE to start the server. It works fine when I use a tunnel but that option is extremely slow when reloading changes. It still doesn't work with localhost or LAN. Is it possible that I have to use something like port forwarding to open this port on my router?
Also: When I typ: localhost:19000 in Google Chrome I get some Json returned. But this doesn't work when I'm in Expo!
Fixed the problem! I just found the following solution:
Go to cmd and type ipconfig
get the ip4 adress of the virtual machine and copy it.
Than go to computer > properties > advanced system settings > environment variables and add the following system variable: REACT_NATIVE_PACKAGER_HOSTNAME
As the value for the variable I had to paste the ip4 of the virtual machine.
I had the same problem. My issue was that VirtualBox had installed a couple of virtual ethernet adapters and NPM was choosing one of those. After disabling those in Control Panel > All Control Panel Items > Network Connections, the Expo app connected as expected.
Windows firewall blocks the request. You can define two inbound rules for Port 19000 and 19001
You can configure the port by defining a .exprc file containing:
{
"manifestPort": 8000
}
I had same issue. I disable all other network adapter and left WIFI adapter enable.
secondly you can also change the priority of adapter it also gonna work
Related
I've have a problem when I use the --livereload in following command: ionic run android --livereload. If I does not use --livereload the app works fine. This also only occurs when I test on a physical device. On an emulator there are no issues.
I've already tried several options like:
<preference name="loadUrlTimeoutValue" value="700000" />
Or the index to main.html solution like explaned here: How to fix the connection to the server was unsuccessful. (file ///android_asset/www/index.html)
Does anyone know what is the cause of the problem and how to solve it?
Well it seems like your physical device is not able to communicate with machine. Reason could be
Port not accessible because of any firewall restriction
Both under different networks, therefore machine's IP is not accessible from device.
When you run "Ionic cordova run android --l", you get an IP address in command line, did you try accessing that IP along with port from device's browser?
After a time I've noticed that when I've closed my terminal window in Intelij the problem never occured. Now I end the process and then close the terminal.
It seems that somehow the process remained active after "stopping" it. I'm running my ionic run android --livereload --target=emulator-5554 command in a new terminal now.
I'm using port 8088 instead of 8081 for my Android emulator (using these instructions), running on Windows 10.
The React Native Debugger is now throwing a ERR_CONNECTION_RESET error, which I suspect is because it's trying to connect to port 8081 (photo below).
How can I set the Debugger to use port 8088?
Note: I cannot use port 8081 because my school requires McAfee antivirus which uses the port. I promise, I wish I could just use 8081
Edit: Added emulator error
UPDATE
It appears that this is a known issue. Luckily, there is a pull request out to fix it.
In the meantime, I ended up stopping the program that was on port 8081 using Windows Services (search for 'services' in the Windows 10 search bar).
This issue is fixed in react-native 0.42 and above.
I'm using Jenkins for continous integration on an android emulator to run instrumentation tests with the espresso framework. Unfortunately the server is not able to connect to the emulator. I have a master instance which delegates the push events from GitHub to the slave instance where the android sdk is installed. I installed the android-emulator-plugin and configured it like described. At first the Jenkins starts the emulator, but it cannot connect to it afterwards. This is the result:
I also cannot connect to the emulator when I'm on the slave machine. But if I use 127.0.0.1 instead of localhost the adb tool can connect to the emulator:
Is it possible to use 127.0.0.1 instead of localhost with the android-emulator-plugin? I already specified the enviorment variables $ANDROID_AVD_DEVICE and $ANDROID_SERIAL with no result. Any ideas?
I was fighting with it whole day. Just try to comment ipv6 in your /etc/hosts.
I fixed the problem by myself. I have checked out a fork on GitHub, which uses 127.0.0.1 instead of localhost. This did work for connecting to the emulator but not for running the instrumentation tests. I do not use Jenkins plugins for the connection anymore. I make the build with a shell script which contains all commands to start the AVD and the gradle tasks. Works fine for me. But thank you for the advice. Maybe I will try to comment ipv6 aswell, if I have the time to work on the Jenkins.
I used the react-native Android demo project AwesomeProject and within the project I executed:
react-native start
In a second terminal:
react-native run-android
To start webserver and install the Android APK. The default webserver configuration is localhost:8081, how can I modify the webserver port, and how do I update recording of the IP & Port in Android project.
Edit:
I just found out that can modify ip address in Android debug setting, it seems "getDebugServerHost" is a private API, does Facebook provide any API to change ip&port?
As OP commented on MossP's answer, this can now be achieved using the debug_http_host shared preference (see this issue).
So, if you wanted to use, say, port 8082, you could add an onCreate method to your MainActivity.java file, which might look something like this:
#Override
protected void onCreate(Bundle state){
super.onCreate(state);
SharedPreferences preferences =
PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
preferences.edit().putString("debug_http_host", "localhost:8082").apply();
}
Of course not forgetting to import android.content.SharedPreferences, android.os.Bundle, and android.preference.PreferenceManager.
This would make your app try to access the packager at the desired port instead of 8081.
Then you'd just make sure to start the packager with --port 8082 (as described here), and you should be all set.
(Unless you happen to be using Nuclide, which is a whole other story).
Note that up until React Native 0.46, this would only allow one to run the app successfully, but still didn't make it possible to actually attach a debugger on a non-standard port. As of React Native 0.46, attaching a debugger should also work.
Update: See Tomty's answer for the current recommended way to do this in 2019.
Unfortunately, the port is currently (2015/09/23) hardcoded. I believe this will be changed in time as it already has an Issue raised from a high level contributor to the project.
https://github.com/facebook/react-native/issues/2704
There is a small work around for this. Anyone running this on a physical device(or even otherwise) can restart their adb session using a different port.
eg.
react-native start --port=1234
On a different cmd/terminal window.
react-native run-android
After which I am greeted by these messages.
BUILD SUCCESSFUL
Total time: 22.589 secs
Running C:\SDK/platform-tools/adb -s VY0025160560725694 reverse tcp:8081
tcp:8081
This runs it on default reverse port of 8081, which is blocked by McAfee.
Work around:
adb reverse tcp:8081 tcp:1234
Try it out. It works for me.
Note: You may have to kill and re-open the app.
Currently I am unable to provide an answer for an emulated device since I do not have one installed on my system. But the symantics should be similar.
Note: This may break automatic code updates using watchman.
As stated in https://facebook.github.io/react-native/docs/debugging.html#accessing-the-in-app-developer-menu,
You can access the developer menu by shaking your device or by
selecting "Shake Gesture" inside the Hardware menu in the iOS
Simulator. You can also use the ⌘D keyboard shortcut when your app is
running in the iOS Simulator, or ⌘M when running in an Android
emulator. Alternatively for Android, you can run the command adb shell
input keyevent 82 to open the dev menu (82 being the Menu key code).
So on iOS device shake it, on iOS emulator press control D, on Android emulator control M, on Android device do adb shell input keyevent 82
Then in the menu that opens, go to Dev Settings, debug server & host port for device, and edit the IP and port.
ps: will only work for non production
On Mac :
go To Wifi
Open network preferences
Wi-Fi is connected to {wifi name} and has the IP address {xxx.xxx.x.x}.
Get your ip address .
Go to application on devices
go to Dev Setting
Tap to Debug server host & port for device
Fill your IP address and port is 8081 (example ipaddress:8081) .
This is an extension of Tomty's answer. Check out an example project here:
npm i #nick-bull/react-native-debug-address
# DEBUG_HOST=127.0.0.1:8081 npx react-native start --port 8081
# or, equivalently
DEBUG_PORT=8081 npx react-native start --port 8081
npx react-native run-android --port 8081
I tried all the possible options given on net and on this site, but none of them worked.
I am getting:
Launch error: Failed to connect to remote VM. Connection timed out.
when I am trying to debug my application on my mobile device.
the application runs properly with out any issue when I am running normally
I have used at lease these links by now:
How to resolve "Waiting for Debugger" message?
Eclipse issue - Launch error: Failed to connect to remote VM. Connection timed out
Eclipse Error: "Failed to connect to remote VM"
Launch error: Failed to connect to remote VM
https://forums.oracle.com/forums/thread.jspa?threadID=653343
None of the above seem to work.
Go to Window -> Preferences -> General -> Network Connections, and check if there is any proxy set here, change the 'Active Provider' to be 'Direct' and try again.
I dont know why, but this works for me:
First Run(or Debug) your application in an emulator and then Debug the application on the device (without closing the emulator).
let me know if this works for you.
I've been having the same frustrating problem. I finally found something that is working for me: making sure localhosts is being resolved correctly (and really explicitly).
Test to see if it works when your development machine is not connected to the net (no WiFi, no network cables). If it does work under those conditions, then it may be that you need to make sure that addresses are resolving to localhost properly. The messages that DDMS and adb.exe use for debugging and communicating to the VM must properly resolve to localhost on your machine. (Yes, it's odd that other commands using DDMS & adb work just fine but debugging doesn't. Seems that something in DDMS or adb needs to be standardized so they all work under the same conditions.)
If you need to make sure that things are resolving to localhost properly:
1) Make sure that this line is in your /Windows/System32/drivers/etc/hosts [windows] (or etc/hosts [*nix] file:
127.0.0.1 localhost
(you can have any amount of whitespace between "127.0.0.1" and "localhost")
2) If that doesn't work, then you may need to also add your PC's IPv4 address to the hosts file, and resolve it to localhost. (You can find out the IPv4 address for your machine with the ipconfig command.) If, for example, your machine's IPv4 address is 192.168.1.100 then you'd add the line
192.168.1.100 localhost
to your hosts file. (You can add it below the "127.0.0.1 localhost" line in the file.)
I had (1) in my hosts file but it still wasn't working (unless my PC wasn't connected to the net). I tried (2) on a bit of a guess, and that worked for me.
BTW: You can verify that adb (and your emulator if you're running one) is listening on ports by using the netstat -b command. (Note that on Win7 you need admin privileges for the -b option. I open a command window using "Run as Administrator.")
May seem like an obvious answer but make sure you don't have two emulators running - 5554; 5556; ... The debugger has difficulty setting the port when it doesn't know which one to connect to.