Flutter release 网络请求错误问题
在测试环境中网络请求正常,但是 release 之后,出现如下问题:
E/flutter (17981): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: SocketException: Failed host lookup: 'api.dev.echoes.tech' (OS Error: No address associated with hostname, errno = 7)
E/flutter (17981): #0 IOClient.send (package:http/src/io_client.dart:33)
E/flutter (17981): <asynchronous suspension>
E/flutter (17981): #1 BaseClient._sendUnstreamed (package:http/src/base_client.dart:169)
E/flutter (17981): <asynchronous suspension>
网络地址找不到。
解决方法:
在路径为 android/app/src/main/AndroidManifest.xml
的配置文件添加权限配置:
<application
android:name="io.flutter.app.FlutterApplication"
android:label="echo"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
增加最后一行: <uses-permission android:name="android.permission.INTERNET" />
即可。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论