adb cannot bind 'tcp:5037' - android

It used to work fine, but today after I connected my Android phone to my machine, and run adb devices, I got the following error:
* daemon not running. starting it now on port 5037 *
cannot bind 'tcp:5037': Address already in use
ADB server didn't ACK
* failed to start daemon *
error: cannot connect to daemon: Operation timed out
How to solve this problem? (I am using a MacBook)

Try with following commands
Find port details by List Open Files lsof command.
sudo lsof -i :5037 and find PID and kill it.
kill -9 <pid here>
Example: kill -9 4363
Then start adb server. adb devices command.

Kill the Adb server and restart.
adb kill-server
adb start-server

I managed to solve this problem on MacBook by first running the following command to list the process which is using port 5037
lsof -n -i4TCP:5037 | grep LISTEN
Then, I kill it:
kill -9 <PID>
Then, adb devices works!

Android Studio Terminal
$ adb devices
List of devices attached
adb server is out of date. killing...
cannot bind 'tcp:5037': Address already in use
ADB server didn't ACK
* failed to start daemon *
error:
error:
OS Terminal
$ adb devices
List of devices attached
adb server is out of date. killing...
* daemon started successfully *
Finally test again at the IDE terminal
$ adb devices
List of devices attached
GL

it is clear that Address already in use. busybox netstat -antp to check who is using the port.

I've fixed the problem by updating the Android SDK.
android update sdk --no-ui
Additionally, I've updated the Platform Tools to the newest version.
If this doesn't work, redownload android sdk.
wget http://dl.google.com/android/android-sdk_r24.2-linux.tgz
tar -xvf android-sdk_r24.2-linux.tgz cd android-sdk-linux/tools
install all sdk packages
./android update sdk --no-ui

I tried it at the OS Terminal, worked.
Try on the OS terminal first

Running the following command at the OS bash helped solve the issue:
sudo adb start-server

I ran adb kill command and then it started working fine
adb kill-server
adb start-server

Related

adb devices hangs and after a while times out on WSL2

Running on Ubuntu 20.04 (WSL2):
➜ ~ adb --version
Android Debug Bridge version 1.0.41
Version 33.0.1-8253317
Installed as /home/eliya/dev/Android/platform-tools/adb
Running
➜ ~ adb devices
adb W 04-28 16:43:11 20145 20145 network.cpp:149] failed to connect to '172.23.160.1:5037': Connection timed out
* cannot start server on remote host
adb: failed to check server version: cannot connect to daemon at tcp:172.23.160.1:5037: failed to connect to '172.23.160.1:5037': Connection timed out
Running
➜ ~ adb start-server
adb W 04-28 16:47:17 21475 21475 network.cpp:149] failed to connect to '172.23.160.1:5037': Connection timed out
* cannot start server on remote host
error: cannot connect to daemon at tcp:172.23.160.1:5037: failed to connect to '172.23.160.1:5037': Connection timed out
But when I run it as root, it seems to work fine:
➜ ~ sudo adb devices
List of devices attached
XXXXXXXXXXXXXX device
How can I make adb to work without sudo permissions?
Update 1
running adb -H localhost ... seems to be ok. What am I missing here?
Update 2
Running in Windows:
PS C:\Users\coeli> adb start-server
and then in WSL2 (hangs for a while and then fails):
➜ ~ adb devices
List of devices attached
* cannot start server on remote host
error: cannot connect to daemon at tcp:172.23.160.1:5037: Connection timed out
If you want WSL to be able to talk with the adb server running in Windows, you have to start the server in such a way that it will listen on all interfaces, not just the default one. This is done with -a, like so:
.\adb.exe -a nodaemon server start
You can also put a -P in there if you want to use something other than the default port of 5037, like this:
.\adb.exe -a -P 5037 nodaemon server start
If you still have problems, double-check your Windows Firewall. However, since this is all local interface stuff, that shouldn't be a factor in most installations.
I think I may have found a fix for this. In my case, the issue was caused by not installing sdkmanager properly. I used openjdk11 instead of openjdk8, which is required by the sdkmanager to run properly. In anycase, following this tutorial https://gist-github-com.translate.goog/georgealan/353a548814fe9b82a3a502926c7a42c6?_x_tr_sl=auto&_x_tr_tl=en&_x_tr_hl=en-US&_x_tr_pto=wapp#passo-4%C2%BA
should allow you to get it up and running without needing to use sudo commands. Article is for ReactNative but you dont need to follow the whole thing

Running "adb shell" restarts ADB

I am using Android Studio 2.2.3. Everything is up to date.
Running "adb shell" on Terminal in Android Studio generates the following:
adb server is out of date. killing...
* daemon started successfully *
error: device not found
To reconnect the device, I have to run "adb kill-server" first.
This makes running shell commands impossible.
Could anyone offer a tip on how to fix this?
From Android Studio Terminal run
$ $ANDROID_HOME/platform-tools/adb shell
this ensures you will be using the same adb.

Android Studio Error: Adb refused a command

I just changed my PC, and now I have a problem with Android Studio, every time i try to run or compile an app it install it correctly, but then it cannot start the main activity of the app, if you need it this is the full Android studio output:
Waiting for device.
Target device: samsung-gt_i9000-3733E37B1ACB00EC
Uploading file
local path: C:\Users\Federico\swagmasta\TurnarioConapo1.0\app\build\outputs\apk\app-debug.apk
remote path: /data/local/tmp/feddycapdev.conapo.turnario
Installing feddycapdev.conapo.turnario
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/feddycapdev.conapo.turnario"
pkg: /data/local/tmp/feddycapdev.conapo.turnario
Launching application: feddycapdev.conapo.turnario/feddycapdev.conapo.turnario.MainActivity.
DEVICE SHELL COMMAND: am start -D -n "feddycapdev.conapo.turnario/feddycapdev.conapo.turnario.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Error: Adb refused a command
I tried to manually run am start -D -n "feddycapdev.conapo.turnario/feddycapdev.conapo.turnario.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER from the adb shell, and it work correctly, some ideas on how could i fix it?
UPDATE : I tried running as admin, rebooting PC, reconnecting cable, killing all the adb.exe processes, killing the adb server and restarting it, noone of this worked.
Maybe it's a problem of driver? I'm using a Samsung Galaxy S for debugging, at the beginning the PC didn't recognized it, so I installed samsung USB driver, so maybe that's the real problem, but if i can install app to my device via adb the driver should be working right?
Please kill and start adb server from console or terminal using following commands:
adb kill-server
adb start-server
If it does not help try to restart your computer.
If you are getting
adb command not found
error then you have to go in platform-tools directory in Android SDK.
hope it helps!
It could be blocked by some other instance of adb.
Look into your task manager if you are not running another instance of adb.

Changing default port (i.e. 5037) on which adb server runs

I am a budding android developer and if there is no easy way of configuring the adb server to run on another port then the inflexibility of the tools will force me to quit android app development.
A web search did not return any solutions.
I also searched for '5037' in all files in android sdk directory but did not find a setting there.
Use the environment variable ANDROID_ADB_SERVER_PORT to select the port.
The following works under bash:
$ export ANDROID_ADB_SERVER_PORT=12345
$ adb start-server
* daemon not running. starting it now on port 12345 *
* daemon started successfully *
$ adb devices
List of devices attached
TA2070M5O6 device
$ ANDROID_ADB_SERVER_PORT=6789 adb devices
* daemon not running. starting it now on port 6789 *
* daemon started successfully *
List of devices attached
In another terminal I ran:
$ ANDROID_ADB_SERVER_PORT=6789 emulator ...
Back to original terminal:
$ ANDROID_ADB_SERVER_PORT=6789 adb devices
List of devices attached
emulator-5554 device
$ adb devices # ANDROID_ADB_SERVER_PORT was exported as 12345
List of devices attached
TA2070M5O6 device
I found this via the Jenkins Android Emulator Plugin as I noticed it was running adb on a different port.
With the latest adb version,
Use option -P (Note: Caps P)to start adb server in a specific port.
For Example, Try
$adb -P 5038 start-server
It will list the devices attached to this specific adb server. If the adb server is not running then it will start a new adb server with the given port number.
Hope it helps someone reading this post.
Thanks.
In Windows, go to Environment Variables – Add a new one called ANDROID_ADB_SERVER_PORT
and set it to whatever you want, I've set to 5038.
Should look like this:
Solved it for me.
There is another variable that supports this for connecting to a different machine's adb:
ADB_SERVER_SOCKET=tcp:some.other.host:1234 adb devices
To use it, you need to start adb on the other host with -a and probably background it too:
( adb -a -P 1234 nodaemon server & ) &

Adb won't start

Running Vista, tried starting adb from shell as admin get daemon not running starting it now
ADB server didn't ACK
* failed to start daemon *
Any help for this?
This problem has annoyed me for a long time. In addition to the above answer, use these tips:
Create a bat file with the following and run it. This bat file will solve most of your adb problems.
tskill adb
cd \tools\
adb kill-server
adb start-server
ddms
Use the command netstat to monitor the state of connections (adb uses 5037)
If the bat file doesn't work try: disconnect-reboot phone-connect. (hint: use `adb reboot' if adb is responding at all, if not do it the old fashioned way)
Sometimes Windows can be funny. Reboot the machine.
Turn on USB Debugging Mode
Download the Android SDK and unzip
Uninstall all "Android *" from Device Manager
Do an "Add Hardware" from Control Panel, choosing "Install the hardware...
(Advanced)"
Select "Android USB Devices" and click "Next"
Click "Have Disk" and enter the path where the SDK was unzipped
Still not working ? Factory reset the phone.
MTP detection delays ADB. Sometimes you if need boot time logs you may have to disable the MTP driver in Device Manager (Windows)
This is a brilliant patch for adb when you get the error :
Adb connection Error:An existing connection was forcibly closed by the remote "
I was unable to use adb. I got the following error, both on the command line and in eclipse.
* daemon not running. starting it now on port 5037 *
ADB server didn't ACK<br>
* failed to start daemon *
That is, adb start-server failed even after rebooting. To diagnose the problem, I found that you can run adb with the following arguments:
adb nodaemon server
And it will print out the reason that it cannot run. In my case, it was a blank line in the adb_usb.ini file.
You may have a stuck copy of the adb daemon in memory. Try removing it with Task Manager, or reboot, and see if that helps.
For whoever is using Android Studio and MAC. This is what worked for me:
In Android Studio: Tools -> Android -> Uncheck "Enable ADB Integration"
In terminal: "adb kill-server"
In Android Studio: Tools -> Android -> Check "Enable ADB Integration"
In terminal: "adb start-server"
The top answer is Windows-specific but this has a decent amount of Google visibility, so if you're running a *nix-like machine (I'm on a Mac), the steps are similar:
$ killall adb
$ cd <PATH_TO_SDK>/platform-tools/
$ adb kill-server
$ adb start-server
Or, if you're like me and just want to access adb no matter your current directory, add
export PATH=${PATH}:<PATH_TO_SDK>/platform-tools/
to your ~/.bash_profile.
> killall adb
> adb start-server
Restart Eclipse.
Basically adb is running on another process on your box, and you need to kill it, and start up the daemon again, since they're both trying to bind to the same port (:5037). In my case, I had another window open to :5037, and forgot about it. Wondered why I couldn't stop and start as usual. By going "killall" you make sure you're terminating all processes. You can also go into the CPU's processes and force quit.
adb nodaemon server
helps. In my case, I had edited ~/.android/adb_usb.ini, and added 0x1949 at the end to enable debugging on the Kindle Fire. Sadly, it could not handle the newline(s) I put in after the 0x1949
1.$ apt-get remove android-tools-adb
2.$ cd $PATH_TO_SDK/platform-tools/
3.$ ./adb devices
You will see like this:
daemon not running. starting it now on port 5037 * cannot bind 'tcp:5037' ADB server didn't ACK * failed to start daemon *
That show what errors.
Now you reset you PC, it will well.
Or
# lsof -i:5037
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
wineserve 3609 root 268u IPv4 20118 0t0 TCP localhost:5037 (LISTEN)
#
You will know which software use the port.
To avoid this simply change the following values in your host_config.xml:
<!-- Number of tests executed between reboots. A value <= 0 disables reboots. -->
<IntValue name="maxTestCount" value="10000" />
<!-- Max size [tests] for a package to be run in batch mode. -->
<IntValue name="maxTestsInBatchMode" value="100000" />
<!-- Max time [ms] between test status updates. -->
<IntValue name="testStatusTimeoutMs" value="600000" />
I had the same problem. I had improperly edited my adb_usb.ini file (I had two carriage returns at the end of the file...yes this was hard to find.)
This file is located somewhere similar to /Users/{user-name}/.android/adb_usb.ini
(replace {user-name} with your own user name)
Make sure the file reads EXTACTLY (No spaces/carriage returns/line breaks before or after):
'# ANDROID 3RD PARTY USB VENDOR ID LIST -- DO NOT EDIT."
'# USE 'android update adb' TO GENERATE."
'# 1 USB VENDOR ID PER LINE."
(IMPORTANT!!! There are no ' (apostrophes) in the actual file, this was the only way for me to post this without it interpreting the # for BOLD).
Hope that helps someone
If you're using Android Studio, if
you have the "Device chooser" dialog open
you try to run "adb devices" from your command line
it leads every single time to the following error
adb server is out of date. killing...
cannot bind 'tcp:5037'
ADB server didn't ACK
* failed to start daemon *
error:
SOLUTION (easy and quick)
Close the "Device chooser" dialog. My guess is that it tries to take over the adb connection in a.. very intensive way.
I'm facing this issue with Genymotion, so I've replaced it's adb with my current adb. For reference:
cd $GENYMOTION_HOME\tools
mv adb adb-old
ln -s $ANDROID_SDK\platform-tools\adb adb
There is yet another possibility. If you have installed any permission managers, like Advanced android permission manager , the adb may fail.It was my case. Uninstalled the app and then no issues.
It seem are the same,
but sometime, the command adb kill-server have no effect (at least is in my case).
So, i have tried other way.
You can check this way: https://stackoverflow.com/a/34627522/5597864
In a console, try:
taskkill /F /T /IM adb.exe
Do this many times, until it says ERROR: The process "adb.exe" not found.
Then
adb devices
The adb server is not running. you can open the command line window in Windows to check which process is using the 5037 port, remember the process number.
netstat -ano |findstr "5037"
Then use the Ctrl+alt+delete to open the process manager to kill the process which is possessing the 5037 port. You maybe need to try this several times until the 5037 port is free to use.
Open Command
Navigate your adb.exe file where is located
Reach into the file on command
adb kill-server
adb start-server
When it additionally says that adb server is out of date. killing... it kills it for you.
The problem is it restarts as soon as was killed.
So you should consider finding the adb.exe wherever it could be.
The simplest way to do that is opening a Task Manager, finding an adb.exe process -> RMB -> Open file location -> delete it from there. Unless it's not needed, in this case you should update it.
In my case it was in C:\Windows\ and came with their Visual Studio.
If you are getting the error cannot bind 'tcp:5037' and you are using any Linux distribution such as Ubuntu,
Kill old ADB process:
fuser -n tcp -k 5037
This will kill the adb process at port 5037 and then,
Start ADB:
adb start-server
Usually the answers given here worked for me, but today they didn't. My problem was fixed by updating the emulator and SDK to the latest versions from the SDK manager.
On A Mac or Unix
For those of you coming here with on Mac or Unix, the following worked for me:
adb kill-server
adb server

Categories

Resources