本文介绍了升级到Cordova Android 8后,为什么会看到net :: ERR_CLEARTEXT_NOT_PERMITTED错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升级到 Cordova Android 8.0后,尝试连接到http://目标时出现net::ERR_CLEARTEXT_NOT_PERMITTED错误.

After upgrading to Cordova Android 8.0, I am seeing net::ERR_CLEARTEXT_NOT_PERMITTED errors when trying to connect to http:// targets.

那是为什么,我该如何解决?

Why is that and how can I resolve this?

推荐答案

Cordova Android平台中的默认API级别已升级.现在,在Android 9设备上,默认情况下禁用.

The default API level in the Cordova Android platform has been upgraded. On an Android 9 device, clear text communication is now disabled by default.

要再次允许纯文本通信,请将application标记上的android:usesCleartextTraffic设置为true:

To allow clear text communication again, set the android:usesCleartextTraffic on your application tag to true:

<platform name="android">
  <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
      <application android:usesCleartextTraffic="true" />
  </edit-config>
</platform>

如注释中所述,如果您之前未定义android XML名称空间,则在构建过程中将收到error: unbound prefix.这表明您需要将其添加到同一config.xml中的widget标签中,如下所示:

As noted in the comments, if you have not defined the android XML namespace previously, you will receive an error: unbound prefix during build. This indicates that you need to add it to your widget tag in the same config.xml, like so:

<widget id="you-app-id" version="1.2.3"
xmlns="http://www.w3.org/ns/widgets"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cdv="http://cordova.apache.org/ns/1.0">

这篇关于升级到Cordova Android 8后,为什么会看到net :: ERR_CLEARTEXT_NOT_PERMITTED错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 02:25