Android连不上模拟器(unable to connect to adb)

一,症状

在debug的时候,偶尔出现如下报错:

unable to connect to adb ,check the event log for possible issues verify that your 
localhost entry is pointing to 127.0.0.1 or ;;for ipv4or ipv6,respectivele


二,诊断一:端口被占用


解决方案:

第一步:查找占用5037端口的进程

mac下执行如下命令:

lsof -i :8080

Android连不上模拟器(unable to connect to adb)_第1张图片

第二步:杀死第一步找到的进程

kill -9 4064


三,诊断二:adb冲突


Genymition有自己的adb,在运行了Genymition后adb的5037端口就被占用了,sdk的adb就运行不起来

解决方案:

将genemotion的adb设置为sdk中的adb

第一步,打开下图中的 Settings

Android连不上模拟器(unable to connect to adb)_第2张图片

第二步,设置genemotion的adb为sdk中的adb

Android连不上模拟器(unable to connect to adb)_第3张图片

第三步,在命令行界面,在sdk的platform-tools文件夹下执行命令
adb kill-server
adb start-server
第四步 重启genemtion 和 Android studio

### 然而,有时,现实却是这样的: ![在这里插入图片描述](https://img-blog.csdnimg.cn/20190925105315498.png)

四,诊断三:以上都不管用怎么办


有时候,上面的方法会管用,但也有不管用的时候,咋办呢?

只能不停的试喽。

比如我最近一次遇到这种情况,我的解决路径是这样的:

  1. 按照诊断二切换adb
  2. 重启genemotion,重启Android studio
  3. 我靠,不行
  4. 把adb切回来,相当于撤销第一步的操作
  5. 重启genemotion,重启Android studio
  6. 草泥马,可以了

Android连不上模拟器(unable to connect to adb)_第4张图片

你可能感兴趣的:(Android)