具体操作就是在flutter项目下创建/android/app/src/main/res/xml/network_security_config.xml
文件,填上配置内容:
<?xml version="1.0" encoding="utf-8"?> <network-security-config> <base-config cleartextTrafficPermitted="true"> <trust-anchors> <certificates src="system" /> <certificates src="user" /> </trust-anchors> </base-config> </network-security-config>
然后修改/android/app/src/main/AndroidManifest.xml
文件,在application
节点加入以下两个属性即可:
android:usesCleartextTraffic="true" android:networkSecurityConfig="@xml/network_security_config"
之后在控制台执行flutter clean
,重新run,就可以看到App里的webview能正常打开HTTP网站了,妙啊~