Cordova ionic应用程序不适用于Android 9&&;10

Cordova ionic应用程序不适用于Android 9&&;10,android,cordova,ionic-framework,android-9.0-pie,android-10.0,Android,Cordova,Ionic Framework,Android 9.0 Pie,Android 10.0,我的ionic应用程序不在android 9设备上运行,在版本低于9的android设备上运行良好。 加载登录页时,应用程序未连接到后端。 有什么想法吗 我使用的环境: 离子型: 爱奥尼亚(爱奥尼亚CLI):^5.0.0 角度^7.2.2 科尔多瓦: cordova(cordova CLI):8.0.0 Cordova平台:安卓8.0.0 系统: Android SDK工具:29 NodeJS:v10 npm:6.2.0原因 这是由于Android 9中启动了以下策略: 打算只使用安全连接连接到

我的ionic应用程序不在android 9设备上运行,在版本低于9的android设备上运行良好。 加载登录页时,应用程序未连接到后端。 有什么想法吗

我使用的环境: 离子型:

爱奥尼亚(爱奥尼亚CLI):^5.0.0 角度^7.2.2

科尔多瓦:

cordova(cordova CLI):8.0.0 Cordova平台:安卓8.0.0

系统:

Android SDK工具:29 NodeJS:v10 npm:6.2.0

原因 这是由于Android 9中启动了以下策略:

打算只使用安全连接连接到目的地的应用程序可以选择不支持到这些目的地的明文(使用未加密的HTTP协议而不是HTTPS)

注意:本节中的指南仅适用于针对Android 8.1(API级别27)或更低版本的应用程序。从Android 9(API级别28)开始,默认情况下禁用明文支持

Cleartext(HTTP通信)现在在默认情况下是禁用的,因此它相当于具有如下内容

<domain-config cleartextTrafficPermitted="false">
  <domain includeSubdomains="true">*</domain>
</domain-config>
network\u security\u config.xml

<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
        xmlns:android="http://schemas.android.com/apk/res/android"
        id="phonegap-plugin-old-http-support-android" version="0.0.1">
    <name>OldHttpSupportPlugin</name>

    <description>Force HTTP for Android 9+</description>
    <license>MIT</license>

    <keywords>cordova,android,http</keywords>
  
    <engines>
        <engine name="cordova" version=">=6.0.0"/>
        <engine name="cordova-android" version=">=7.0.0"/>
    </engines>
  

    <platform name="android">
        <config-file target="res/xml/config.xml" parent="/*">
            <feature name="OldHttpSupportPlugin">
                <param name="android-package" value="YOUR.PACKAGE.plugin.OldHttpSupportPlugin"/>
            </feature>
        </config-file>


        <!-- Source file for Android -->
        <source-file src="src/android/network_security_config.xml" target-dir="res/xml/" />

        <edit-config file="AndroidManifest.xml" target="/manifest/application" mode="merge">
            <application android:networkSecurityConfig="@xml/network_security_config" />
        </edit-config>
    </platform>
</plugin>
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">my.domain.com</domain>
        <domain includeSubdomains="true">example.org</domain>
        <domain includeSubdomains="true">111.222.333.444</domain>
    </domain-config>
</network-security-config>

my.domain.com
example.org
111.222.333.444

您可以在android平台的config.xml部分中添加以下内容:

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

最终结果:

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

...
...

我在爱奥尼亚3和Cordova Android 9.0上遇到了这个问题

我通过将这些行放入
config.xml
文件解决了这个问题。我的解决方案和我的解决方案有点不同

首先,您需要添加
xmlns:android=”http://schemas.android.com/apk/res/android“
在文件开头的
目标中。如果没有此设置,您将无法构建应用程序

您的
目标将如下所示

<widget id="your.id" version="x.x.x" 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">


然后将其添加到
中,您可以共享哪些错误或日志?否则不清楚如何帮助你/您正在对后端使用http请求,而不是https
<edit-config src="platforms/android/app/src/main/AndroidManifest.xml" target="AndroidManifest.xml">
        <application android:usesCleartextTraffic="true" />
</edit-config>