【问题标题】:Android 9: Cleartext HTTP traffic not permitted in webviewAndroid 9:webview 中不允许明文 HTTP 流量
【发布时间】:2019-07-15 13:08:45
【问题描述】:

我正在使用webview_flutter 插件加载托管在 localhost 上的页面(使用 dart 创建的服务器,在手机上),但我得到了net::ERR_CLEARTEXT_NOT_PERMITTED,但我无法使服务器成为 HTTPS。

我已经实现了所有的解决方案here,但这些都不起作用:

  • 添加 network_security_config.xml 文件
  • 添加android:usesCleartextTraffic 选项

还有其他解决方案吗?

【问题讨论】:

  • 你好,解决了吗?在这里面临同样的问题。
  • 我不再需要使用网络服务器,因为 webview_flutter 无论如何都可以加载本地文件。不知道我是怎么错过的。要加载本地存储文件(html、css 和 js),您必须使用 `final directory = (await getApplicationDocumentsDirectory()).path; 提供 .html 文件的完整路径; var url = "file:///$directory/path/to/index.html";` 它会正确加载它
  • 问题是我需要从网络服务器获取内容。
  • 我重新实现了关于这个问题的前 7 个谷歌搜索结果中的所有内容,并且最终奏效了

标签: android http flutter webview android-manifest


【解决方案1】:

我是一名安卓开发者,让我告诉你。

打开android manifest文件(debug和release),添加

android:usesCleartextTraffic="true"

应用程序标签

<application
    android:name="io.flutter.app.FlutterApplication"
    android:label="..."
    android:icon="@mipmap/ic_launcher"
    android:usesCleartextTraffic="true">

发布文件路径android/app/src/main/AndroidManifest.xml 调试文件路径android/app/src/debug/AndroidManifest.xml

【讨论】:

    猜你喜欢
    • 2019-07-16
    • 1970-01-01
    • 2016-10-18
    • 1970-01-01
    • 2020-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多