SocketException: Failed to create server socket(OS Error: Permission denied, errno = 13)

问题:SocketException: Failed to create server socket (OS Error: Permission denied, errno = 13)。

在安卓手机上的表现就是白屏,无法显示页面。

I/flutter (25532): Observatory server failed to start after 1 tries
I/flutter (25532): Observatory server failed to start after 2 tries
I/flutter (25532): Observatory server failed to start after 3 tries
I/flutter (25532): Observatory server failed to start after 4 tries
I/flutter (25532): Observatory server failed to start after 5 tries
I/flutter (25532): Observatory server failed to start after 6 tries
I/flutter (25532): Observatory server failed to start after 7 tries
I/flutter (25532): Observatory server failed to start after 8 tries
I/flutter (25532): Observatory server failed to start after 9 tries
I/flutter (25532): Observatory server failed to start after 10 tries
I/flutter (25532): Observatory server failed to start after 11 tries
I/flutter (25532): Could not start Observatory HTTP server:
I/flutter (25532): SocketException: Failed to create server socket (OS Error: Permission denied, errno = 13), address = 127.0.0.1, port = 0
I/flutter (25532): #0      _NativeSocket.bind (dart:io-patch/socket_patch.dart:736:7)
I/flutter (25532): <asynchronous suspension>
I/flutter (25532): #1      _RawServerSocket.bind (dart:io-patch/socket_patch.dart:1394:26)
I/flutter (25532): #2      _ServerSocket.bind (dart:io-patch/socket_patch.dart:1676:29)
I/flutter (25532): #3      ServerSocket._bind (dart:io-patch/socket_patch.dart:1667:26)
I/flutter (25532): #4      ServerSocket.bind (dart:io/socket.dart:382:27)
I/flutter (25532): #5      _HttpServer.bind (dart:_http/http_impl.dart:2701:25)
I/flutter (25532): #6      HttpServer.bind (dart:_http:229:19)
I/flutter (25532): #7      Server.startup.poll (dart:vmservice_io/vmservice_server.dart:410:36)
I/flutter (25532): <asynchronous suspension>
I/flutter (25532): #8      Server.startup.poll (dart:vmservice_io/vmservice_server.dart)
I/flutter (25532): #9      Server.startup (dart:vmservice_io/vmservice_server.dart:422:23)
I/flutter (25532): <asynchronous suspension>
I/flutter (25532): #10     main (dart:vmservice_io:262:12)
I/flutter (25532): 

原因分析

从log中我们可以看出,错误信息是Permission denied,创建socket服务器失败。做Android开发的同学一看就应该知道了,这是因为没有网络权限。

为什么需要创建服务器呢,这是为了能够让HotReload正常运行。每当代码一修改,保存后会自动把代码push到手机。

解决方法

在Android目录中的AndroidManifest.xml文件中,添加网络权限即可。

<uses-permission android:name="android.permission.INTERNET"/>

参考:https://github.com/flutter/flutter/issues/32602

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值