升级到 Cordova Android 8.0 后,我在尝试连接到 http://
目标时看到 net::ERR_CLEARTEXT_NOT_PERMITTED
错误。
为什么会这样,我该如何解决?
原文由 Oliver Salzburg 发布,翻译遵循 CC BY-SA 4.0 许可协议
升级到 Cordova Android 8.0 后,我在尝试连接到 http://
目标时看到 net::ERR_CLEARTEXT_NOT_PERMITTED
错误。
为什么会这样,我该如何解决?
原文由 Oliver Salzburg 发布,翻译遵循 CC BY-SA 4.0 许可协议
我正在使用 Vue 和 Capacitor 3 运行 Ionic 5,并且在不支持 https 的网站上使用 InAppBrowser 时遇到此错误。对于电容器应用程序,不使用 config.xml
AndroidManifest.xml
而直接编辑 —。
首先,在此处创建网络安全配置文件 YOUR_IONIC_APP_ROOT\android\app\main\res\xml\network_security_config.xml
。
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain>www.example.com</domain>
</domain-config>
</network-security-config>
然后编辑 YOUR_IONIC_APP_ROOT\android\app\main\AndroidManifest.xml
添加 android:networkSecurityConfig="@xml/network_security_config"
到 application
。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.ionic.starter">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<!-- ... -->
</application>
<!-- ... -->
</manifest>
原文由 wsamoht 发布,翻译遵循 CC BY-SA 4.0 许可协议
2 回答1.3k 阅读✓ 已解决
2 回答2.6k 阅读
2 回答1.7k 阅读
1 回答2.1k 阅读
3.5k 阅读
1 回答1.1k 阅读
1 回答1.3k 阅读
3.9k 阅读
2 回答1.3k 阅读✓ 已解决
1 回答3.6k 阅读✓ 已解决
1 回答3.1k 阅读✓ 已解决
1 回答7.7k 阅读
Cordova Android 平台中的默认 API 级别已升级。在 Android 9 设备上,现在 默认禁用 明文通信。
要再次允许明文通信,请将
android:usesCleartextTraffic
application
标签上的 --- 设置为true
:如评论中所述,如果您之前没有定义
android
XML 命名空间,您将在构建期间收到error: unbound prefix
。这表明您需要将其添加到您的widget
标记中相同的config.xml
中,如下所示: