Android Studio error: cannot connect to daemon

假装没事ソ 提交于 2020-07-04 08:03:46

问题


I've been using AS for months, but since two days I get an error when I try to run my app:

Unable to run 'adb': null
'C:\Users\lapof\AppData\Local\Android\Sdk\platform-tools\adb.exe start-server' failed -- run manually if necessary
* daemon not running; starting now at tcp:5037
could not read ok from ADB Server
* failed to start daemon
error: cannot connect to daemon

I've read about a lot of people having this problem, but the solutions provided don't work for me. I read these questions in particular:

  • Daemon not running. Starting it now on port 5037
  • Android ADB - Daemon still not running
  • How to resolve the "ADB server didn't ACK" error?
  • Eclipse error "ADB server didn't ACK, failed to start daemon"
  • Adb won't start
  • How to resolve the "ADB server didn't ACK" error?
  • Daemon not running. starting it now on port 5037 * Cannot open 'nul': The system cannot find the file specified

A lot of answers to these questions say to close adb.exe from task manager, the problem is that adb.exe is not running and if I try to restart it by typing .\adb start-server on a PowerShell window I get the same error.

I also try to restart my PC but it didn't work. On the Android device I'm trying to connect to (Samsung Galaxy S8) I enabled USB debugging. I even tried to eliminate all the authorized devices, but nothing worked.

I checked if the 5037 port was used by other processes, but it is used by adb.exe (and the firewall state on that port is allowed and not limited). By the way, as I said, in the task manager adb.exe is not present.

Last I tried to follow the instructions provided in the last question I linked (basically I re-downloaded adb.exe). Initially I ran .\adb start-server and this strange error occurs:

* daemon not running. starting it now on port 5037 *
* daemon started successfully *
** daemon still not running
error: cannot connect to daemon

and then when I try to run my app on Android Studio it occurs this new error when it tries to start adb:

Unable to run 'adb': null
'C:\Users\lapof\AppData\Local\Android\Sdk\platform-tools\adb.exe start-server' failed -- run manually if necessary
ADB server didn't ACK
* failed to start daemon *

and then if I try to .\adb kill-server and then .\adb start-server or .\adb devices or .\adb usb the same error occurs again. Moreover when I connect my device now it asks me to authorize my PC to connect.

I don't know if this can help, but lately I deactivated a lot of Windows services (but I don't think I deactivated something related to Android Studio).


Details

  • PC: Compaq
  • PC OS: Windows 10 Home
  • Device: Samsung Galaxy S8 (Exynos)
  • Device OS: Android 8.0
  • AS version: 3.0.1

回答1:


I had same problem a moment ago. I solved it :

Run CMD as Administrator

Enter adb devices to CMD.

The output for me is :

C:\WINDOWS\system32>adb devices
List of devices attached
* daemon not running; starting now at tcp:5037
* daemon started successfully
P9BCS87ABS9SCD5 device



回答2:


The solution which worked for me -

Open Command Prompt as administrator and type

adb start-server

That's it




回答3:


I solved the problem on my own.

Out of frustration I opened Control Panel > System and security > Windows defender firewall > Allowed applications and I added adb.exe (both private and public networks).

I came back to Android Studio, ran the app and magically it managed to initialize ADB and my phone connected via USB was there.

I don't really know why this worked, since when I checked in Start > All Programs > Accessories > System Tools > Resource Monitor > Network > Listening Port it said that on port 5037 the firewall was allowed.

Moreover I don't know why up to a week ago all worked fine and now I had to do this process to make it work.

If someone more experienced manages to explain this behaviour better I'll update this answer (or accepts his as best answer)




回答4:


  1. SDK Manager -> SDK tools
  2. Uncheck "Android SDK Platform - Tool"
  3. Click Apply



回答5:


After using Android Studio and Emulator without any problems, suddenly it stop to connect to the Emulator, even adb server was running (killing and starting), firewalls raised for all the programs (adb.exe, qemu-system-x86_64.exe, studio64.exe, etc), port 5037 freed, uninstalled and installed again the programs, even the whole Android Studio from scratch. I got verything running OK, but no connection between AS and Emulator.

The solution to my problem was to run Android Studio AS ADMINISTRATOR, it seems that when I updated the program to 3.5.2 somehow the status changed, causing me the problem.

Hope this help anyone out there like me that passed several days trying all what is written on Internet to fix the issue.



来源:https://stackoverflow.com/questions/52173657/android-studio-error-cannot-connect-to-daemon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!