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

4

我在Android Studio运行应用程序时遇到了问题。当我按下Run按钮时,“选择部署目标”对话框弹出,但我从未看到任何模拟器或设备出现。事件日志不断打印以下内容:

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-native项目,但是在直接使用Android Studio时会出现以下问题。我尝试在Android Studio中创建新项目,但结果仍然相同。我认为这个问题始于我从Android Studio 3.0更新到3.1。你有什么解决方法或获取更多信息的想法吗?谢谢。
系统信息: MacOS High Sierra 10.3.14 Macbook Pro (Late 2011)
软件信息: Android Studio 3.1.2 Java 9.0.4
4个回答

8

我曾经遇到过同样的问题,我通过删除/etc/hosts文件中的0.0.0.0映射来解决它。

早些时候,我的/etc/hosts文件中有一个映射0.0.0.0 localhost


1
这个可以工作。谢谢。我想知道为什么这个映射开始成为一个问题,因为我已经用了很长时间了。 - Tyrice Clark
有人能解释一下为什么这是个问题,以及如何通过添加或删除/etc/hosts中的内容来解决这个问题吗? - RamPrasadBismil

4

我在Mac上也遇到了类似的问题,通过在/etc/hosts文件中添加127.0.0.1 localhost这一行来解决。


2

我在Mac上也遇到了类似的问题,通过从/private/etc/hosts文件中移除::1 localhost这一行解决了它。


0
我遇到了同样的问题。我通过将默认AVD中的0.0.0.0更改为10.0.2.2来解决它。我将使用0.0.0.0并且可以工作。根据您的需要添加端口。在network-security-config中也添加它以允许明文传输。
10.0.2.2是您主机环回接口的特殊别名(在开发机上为127.0.0.1)。
如果您使用的是Genymotion模拟器,请使用10.0.3.2。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接