离子3错误:找不到资源xml / network_security_config

时间:2019-10-12 21:17:05

标签: cordova ionic-framework ionic3

当我尝试运行“ ionic cordova build android”时,出现此异常:

  

Anroid资源链接失败   J:\ workspaces \ APCO \ App \ apco \ platforms \ android \ app \ build \ intermediates \ merged_manifests \ debug \ AndroidManifest.xml:22:   AAPT:错误:dresource xml / network_security_config(又名   找不到io.ionic.starter:xml / network_security_config。

问题是,我在“ ... APP-FOLDER \ platforms \ android \ res \ xml”和“ ...... APP-FOLDER \ resources \ android \ xml”中包含network_security_config.xml。

我的AndroidManifest.xml:

...
<application
        android:debuggable="true"
        android:hardwareAccelerated="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:networkSecurityConfig="@xml/network_security_config"
        android:supportsRtl="true" >
...

我的config.xml:

 <platform name="android">
 <edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
      <application android:networkSecurityConfig="@xml/network_security_config" />
 </edit-config>
 <resource-file src="resources/android/xml/network_security_config.xml" target="res/xml/network_security_config.xml" />

1 个答案:

答案 0 :(得分:0)

在config.xml中 替换

<edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
        <application android:networkSecurityConfig="@xml/network_security_config" />
    </edit-config>

使用

<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
        <application android:usesCleartextTraffic="true" />
        <application android:networkSecurityConfig="@xml/network_security_config" />
    </edit-config>

并添加

<resource-file src="resources/android/xml/network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />
在resources / android / xml / network_security_config.xml中

创建新文件 network_security_config.xml

  <?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
    <trust-anchors>
        <certificates src="system" />
    </trust-anchors>
</base-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">localhost</domain>
        <!-- note this is without http -->
    </domain-config>
</network-security-config>