Android Studio -无法连接到设备或模拟器

2w2cym1i  于 2023-11-15  发布在  Android
关注(0)|答案(4)|浏览(150)

我在Android Studio中运行应用时遇到问题。当我按下“运行”时,会弹出“选择部署目标”对话框,但我无法看到任何模拟器或设备出现。事件日志会打印出以下内容并无限期重复:

5/6/18
12:40 PM    Gradle sync started

12:40 PM    Project setup started

12:41 PM    Gradle sync finished in 49s 932ms

12:41 PM    Executing tasks: [:app:generateDebugSources]

12:41 PM    Gradle build finished in 15s 765ms

12:44 PM    Unable to open connection to: localhost/0.0.0.0:5037, due to: java.net.ConnectException: Connection refused

12:44 PM    Connection attempts: 1

12:44 PM    Unable to open connection to: localhost/0.0.0.0:5037, due to: java.net.ConnectException: Connection refused

12:44 PM    Connection attempts: 2

12:44 PM    Unable to open connection to: localhost/0.0.0.0:5037, due to: java.net.ConnectException: Connection refused

12:44 PM    Connection attempts: 3

12:44 PM    Unable to open connection to: localhost/0.0.0.0:5037, due to: java.net.ConnectException: Connection refused

12:44 PM    Connection attempts: 4

12:44 PM    Unable to open connection to: localhost/0.0.0.0:5037, due to: java.net.ConnectException: Connection refused

12:44 PM    Connection attempts: 5

字符串
我可以使用命令行运行React原生项目,但在直接使用Android Studio时会出现这种情况。
我试过在Android Studio中创建新项目,仍然有同样的结果。我相信一旦我从Android Studio 3. 0更新到3. 1,这种情况就开始发生了。
您有解决此问题或获取更多信息的方法吗?
谢谢.
系统信息:
MacOS高级Sierra 10.3.14 MacBook Pro(2011年末)
软件信息:
Android Studio 3.1.2 Java 9.0.4

rggaifut

rggaifut1#

我也有同样的问题,我通过删除/etc/hosts中的0.0.0.0Map来修复它。
之前我在/etc/hosts文件中有一个Map0.0.0.0 localhost

jxct1oxe

jxct1oxe2#

我在Mac上也遇到了类似的问题,并通过将行 127.0.0.1 localhost 追加到/etc/hosts来修复它

slsn1g29

slsn1g293#

我在Mac上也有类似的问题,并通过从/private/etc/hosts中删除行**::1 localhost**来修复它。

vbopmzt1

vbopmzt14#

我有同样的问题.我解决了它使用10.0.2.2而不是0.0.0.0默认AVD.我会打0.0.0.0和工作.添加端口与它如你所愿.添加它在network-security-config太cleartextremicPermitted.
10.0.2.2是您的主机接口的特殊别名(在您的开发机器上为127.0.0.1)
如果您是Genymotion模拟器-使用10.0.3.2.

相关问题