Jenkins cannot connect to android emulator - android

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.

Related

React native expo - Reponse timed out

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

Appium Android bootstrap socket crashed: Error: connect ECONNREFUSED

The problem
I have an already working appium tests suite on my MacOS desktop, but when i try to run the same tests on an Ubuntu 16.04 desktop, I get the following error and appium gets closed automatically.
Android bootstrap socket crashed: Error: connect ECONNREFUSED
Also, just to be clear, i'm not trying to run simultaneous tests, just a single emulated android device.
Environment
Appium version: 1.6.3-Beta. Also tried with 1.5.3 and got the same error.
Last Appium version that did not exhibit the issue (if applicable): Not applicable.
Desktop OS/version used to run Appium: Ubuntu 16.04
Node.js version (unless using Appium.app|exe): 7.6.0. But got the same error with v6.
Mobile platform/version under test: Andorid 6 (Marshmallow)
Real device or emulator/simulator: Simulator
Appium CLI or Appium.app|exe: Appium CLI
Details
Been stuck on this for a few days. Saw some question referring to simultaneous tests on the internet, but its not my case. I'm trying to run my tests on a single emulated android device.
Also tried to change the bootstrap port using the -bp option, and set the localhost address using -a 127.0.0.1, but no success.
Link to Appium logs
https://gist.github.com/BernalCarlos/752efe621a55a2b2b0d07b966c8b5354
Thank you on advance.
Solved the problem by making a fresh install of linux mint 18.1.
Still don't know why this showed up in ubuntu 16.04.
I had the similar problem. Set ADB path in system variable as C:\Users\<username>\AppData\Local\Android\Sdk\platform-tools
This will fix the issue.
I solved the problem adding the appium server argument --suppress-adb-kill-server, it prevents killing the adb server socket

How to modify IP & port use react-native Android?

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

How to fix the error "Unable to open debugger port " in Android Studio?

Error running Android Debugger (8600):
Unable to open debugger port (localhost:8600):
java.net.SocketException "Connection reset"
I was able to fix this with these commands:
adb kill-server
adb start-server
Try Restarting ANDROID STUDIO (Worked for me)
In my case, there was another service running on my laptop(Windows) that was using the port 8600. I opened Task Manager and stopped the service. Now, I could debug my application normally without the above error.
I solve the problem by checking my localhost.
Making sure 127.0.0.1 localhost.
For me this problem started when i upgraded my Android Studio to new version.
Please go to options menu Build and choose Clean Project.
That is it project started to run again and error was gone.
I tried other answers (e.g. restarting Android Studio) but they didn't solve this for me.
I had accidentally selected MTP (Media Transfer Protocol) in my Developer Options/USB Configuration. It started working once I set it to PTP (Picture Transfer Protocol).
EDIT: On reflection it's probably just that I changed the protocol because I've had the same issue since while on PTP. Hence I'm suggesting that the real answer is to change the protocol on the phone and, if you might need it, don't forget to change it back.
It could be that you need to wait for your code to stop compiling before you attached the debugger. I had a similar error and all I needed was patience.
If you using WiFi debug:
Exit ANDROID STUDIO
adb kill-server && adb start-server
adb tcpip 5555
adb connect [your wi-fi IP]:5555
Start ANDROID STUDIO
I did spent quite an amount of time by trying below things:
Re-installing old(3.6.3) and new(4.0.1) Android studio and Android SDK's
checking all the security things in newly installed Mac OS Catalina
Checking all the developer options in my physical android device and AVD
And all the things mentioned in this post as well: https://medium.com/returntrue/android-studio-cant-bind-to-local-8600-for-debugger-%E3%81%A7%E3%83%87%E3%83%90%E3%83%83%E3%82%AC%E3%83%BC%E3%81%8C%E6%B0%B8%E4%B9%85%E3%81%AB%E8%B5%B7%E5%8B%95%E3%81%97%E3%81%AA%E3%81%84%E3%81%A8%E3%81%8D%E3%81%AB%E3%82%84%E3%81%A3%E3%81%9F%E3%81%93%E3%81%A8-8f5dd9c8ca70
Finally a small change in my /etc/host file resolved this issue. I commented from 0.0.0.0 and ::1 for localhost local DNS entries and enabled only 127.0.0.1

Getting "error: closed" twice on "adb reverse"

I am trying to reverse-forward port through ADB, but it just returns cryptic error of error: closed. Normal forwarding works. Session snippet:
$ adb forward tcp:59778 tcp:59778
$ adb forward --list
015d2109ce0c1a0f tcp:59778 tcp:59778
$ adb forward --remove-all
$ adb forward --list
$ adb reverse --list
error: closed
error: closed
$ adb reverse tcp:59778 tcp:59778
error: closed
error: closed
I am connecting via USB to non-rooted Nexus 7 2012 Android 4.4.4 from Windows 7 Pro x64 on Boot Camp.
adb reverse was introduced in Android 5.0
Since adb reverse is not supported in Android versions lower than 5.0, you need to use an alternative method, for example connecting via Wi-Fi instead. If you are using React Native, Facebook has added official documentation to connect to the development server via Wi-Fi. 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.
Follow these steps carefully.
Note: All commands need to run inside a project only.
Run this command first:
npm react-native start
Open another window in the same project and run:
curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
This will create index.android.bundle in the assets folder
Run:
npm react-native run-android
Now you can get apk in the build folder which will work fine.
adb reverse requires Android 5.0+. For devices previous to that, you'll need to use a workaround like so.
If you have busybox installed on your Android device (most Genymotion images do), you can emulate adb reverse using this incantation:
adb shell busybox nc -ll -p {guest port} -e busybox nc {host IP} {host port}
In this case, "guest" is the Android OS running in the emulator and "host" is the computer running the emulator.
cause of adb reverse isnt working on android prior 5 you could propably use adb forward with a service listening on android and tunneling other connections through this inbound connection. I am doing this mostly with ssh, but you would need an ssh server on android. you than can connect using ssh -R incommingreverseportonandroid:hostyouwanttoforwardto:portyouwanttoforwardto sshuseronandroid#localhost -p portyouhaveusedforadbforwaqrdtoaccessandroidssshserver
but i dont know how to enable an ssh server on android and maybe there is a better way cause ssh uses encryption which isnt needed over usb and using up cpu.
i am using this way with my server to share a service when i am forced behind a nat...
hope someone will find a way to bring this teoretical way into practical possibility
Just use 10.0.2.2 instead of localhost/127.0.0.1 for your hostname. It will directly try to connect to the port on the host machine (same affect as reverse).

Categories

Resources