ERR_CLEARTEXT_NOT_PERMITTED - How to add usesCleartextTraffic to AndroidManifest.xml?

What is the right way to add usesCleartextTraffic to Android manifest ? Code below should work but I get errors.

App.appendToConfig(`
    <edit-config file="AndroidManifest.xml" target="/manifest/application" mode="merge">
        <application android:usesCleartextTraffic="true"></application>
    </edit-config>
`);

=> Errors executing Cordova commands:

While adding platform Android to Cordova project:
Error: Unable to graft xml at selector “/manifest/application” from “C:\meteor\myapp.meteor\local\cordova-build\platforms\android\app\src\main\res\xml\config.xml” during config install
at ConfigFile_graft_child [as graft_child] (C:\Users\HXU\AppData\Local.meteor\packages\meteor-tool\1.8.1-beta.20\mt-os.windows.x86_64\dev_bundle\lib\node_modules\cordova-common\src\ConfigChanges\ConfigFile.js:122:19)
at PlatformMunger_apply_file_munge [as apply_file_munge]
.
.
.

1 Like

Are you using Meteor 1.8.1?

If yes, then you need to update the file attribute to this
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">

1 Like

I got unbound prefix error;

BUILD FAILED in 3s
{ Error: cmd: Command failed with exit code 1 Error output:
W:…meteor\local\cordova-build\platforms\android\app\src\main\res\xml\config.xml:69: AAPT: error: unbound prefix.

W:…meteor\local\cordova-build\platforms\android\app\src\main\res\xml\config.xml:69: error: unbound prefix.
W:…meteor\local\cordova-build\platforms\android\app\src\main\res\xml\config.xml: error: file failed to compile.

This works;

App.appendToConfig(`
    <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>
    </edit-config>
`);

4 Likes

Thaaanks, yes it works!!

I have tried this and many other variations with the network security xml as well, nothing it letting it thru.

What’s the error you get ?