最近在做項(xiàng)目的時(shí)候發(fā)現(xiàn)Android studio無(wú)法識(shí)別真機(jī)和模擬器,但是可以電腦卻可以訪問手機(jī)的存儲(chǔ),初步判定是端口占用問題,于是幾經(jīng)尋找,解決了問題。
1、在cmd命令行使用adb kill-server ,adb start-server
網(wǎng)上提供方法是結(jié)束adb之后再啟動(dòng),結(jié)果報(bào)以下錯(cuò)誤:
Unable to create Debug Bridge: Unable to start adb server: adb server version (32) doesn't match this client (39); killing...
adb: CreateFileW 'nul' failed: 系統(tǒng)找不到指定的文件。
2、adb nodaemon server ?得到啟動(dòng)不了的原因
使用adb nodaemon server 會(huì)得到啟動(dòng)不了的原因:
error: could not install *smartsocket* listener: cannot bind to 127.0.0.1:5037: 通常每個(gè)套接字地址(協(xié)議/網(wǎng)絡(luò)地址/端口)只允許使用一次。 (10048)
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
從上面信息可以看出5037端口貌似給占用了
3、找到占用端口的進(jìn)程,并終止該進(jìn)程
5037為adb默認(rèn)端口,若5037端口被占用,
查看占用端口的進(jìn)程PID
C:\Users\xxx>netstat -aon|findstr 5037
? ? TCP 127.0.0.1:5037 0.0.0.0:0 LISTENING 4552
通過(guò)PID查看所有進(jìn)程
C:\Users\xxx>tasklist /fi "PID eq 4552"
映像名稱 ???????????????????????????? ???????????????? PID ????????會(huì)話名 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?會(huì)話# ? ? ? ? ? ?內(nèi)存使用
========================= ======== ================ =========== ============
PPAdbServer.exe ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 4552 ? ? ? Console ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?1 ? ? ? ? ? ? ? ?7,844 K
由此看出PPAdbServer.exe占用了進(jìn)程,在我的電腦對(duì)應(yīng)的是pp助手
所以殺死占用端口的進(jìn)程
C:\Users\xxx>taskkill /pid 4552 /f
成功: 已終止 PID 為 4552?的進(jìn)程。
參考資料:https://blog.csdn.net/u014580040/article/details/79037183
https://blog.csdn.net/wangyanan829/article/details/37593839