Flutter遇到的那些坑

连接不上夜深模拟器

IDEA或者Android Studio无法检测到夜深模拟器。导致无法连接。

根据网上的一些说法,可能是因为Android SDK platform-tools目录下的adb.exe版本和夜深模拟器的adb.exe版本不同导致的。

解决方案

把Android SDK platform-tools目录下的adb.exe复制到夜深模拟器 Nox\bin 目录下,替换掉原来的adb.exe。如果还不行,则重命名为nox_adb.exe,该文件原本可能就存在,直接替换掉即可。(该方法亲测有效。)

E/DartVM ( 3900): vm-service: Error: Unhandled exception: …… app运行后显示白屏

这个问题一开始困扰了好久,每次运行的时候都会报如下的错误,提示连接不上模拟器,发生某某某异常之类的,而且模拟是上的app也一直停止在白屏界面。

E/DartVM  ( 3900): vm-service: Error: Unhandled exception:
E/DartVM  ( 3900): WebSocketException: Invalid WebSocket upgrade request
E/DartVM  ( 3900): 
E/flutter ( 3900): [ERROR:flutter/runtime/dart_isolate.cc(865)] Unhandled exception:
E/flutter ( 3900): WebSocketException: Invalid WebSocket upgrade request
Connecting to the VM Service is taking longer than expected...
Still attempting to connect to the VM Service...
If you do NOT see the Flutter application running, it might have crashed. The device logs (e.g. from adb or XCode) might have more details.
If you do see the Flutter application running on the device, try re-running with --host-vmservice-port to use a specific port known to be available.

在这里插入图片描述

解决方案

打开终端,输入

flutter doctor

看下是否有警告,没有配置NO_PROXY。如果有的话,那问题就是出在这了。

在这里插入图片描述

我们只要在环境变量中配置一下NO_PROXY即可。

对于Window系统的用户:右击我的电脑->属性->高级系统属性->环境变量

选择新建一个环境变量。

在这里插入图片描述

在这里插入图片描述

复制下面内容输入到对应位置。

NO_PROXY
localhost,127.0.0.1

之后一路按确定保存设置。

重新打开一个终端输入flutter doctor,这时候,先前的警告已经没有了

在这里插入图片描述

之后就可以正常运行了。

最好重启一下IDE和模拟器之后,在运行项目,虽然不知道为什么,试了几次,配置好之后都得重修IDE和模拟器才能生效。

对于MAC系统的用户

.bash_profile中添加下面这段

export NO_PROXY=localhost,127.0.0.1

修改完成后

source ~/.bash_profile

最后不出意外应该就能正常用了,如果不行重启电脑

Flutter Provider^4.3.2+3 踩坑记录

Flutter Provider^4.3.2+3 踩坑记录

Flutter开发的app在真机调试下无法加载网络资源

Flutter开发的app在真机调试下无法加载网络资源

如果对您有帮助,点赞关注点一点!!!

猜你喜欢

转载自blog.csdn.net/qq_43058685/article/details/108820143