Ionic 3 error: resource xml/network_security_config not found

When I try to run ‘ionic cordova build android’ I’m given this exception:

Anroid resource linking failed
J:\workspaces\APCO\App\apco\platforms\android\app\build\intermediates\merged_manifests\debug\AndroidManifest.xml:22: AAPT: error: dresource xml/network_security_config (aka io.ionic.starter:xml/network_security_config) not found.

Problem is, I have network_security_config.xml inside ‘…APP-FOLDER\platforms\android\res\xml’ and ‘android/xml’ and ‘…APP-FOLDER\resources\android\xml’.

My 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" >
...

My 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" />

It worked. I found out after remove and add the Android Platform that building in android 7.0.0 was giving the problem, so I only had to build with ‘ionic cordova build android@6.4.0’

To make it work for cordova-android@^8.1.0, make sure you have this configuration:

<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="app/src/main/res/xml/network_security_config.xml" />

For android@^8.1.0 you need to make sure the target is correct: target="app/src/main/res/xml/network_security_config.xml"

5 Likes

this worked for me, thank you :wink: