Read Native android Manifest merger failed (networkSecurityConfig) - android

Note: this is a followup question.
I'm trying to allow http traffic in the android manifest of a react native application.
As explained here, I created a xml file:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">192.168.1.61</domain>
</domain-config>
</network-security-config>
and referenced it in the manifest, in the element :
android:networkSecurityConfig="#xml/network_security_config"
At compile time, I have the following error:
Manifest merger failed : Attribute application#networkSecurityConfig value=(#xml/react_native_config) from AndroidManifest.xml:17:7-67
is also present at AndroidManifest.xml:17:7-67 value=(#xml/network_security_config).
Suggestion: add 'tools:replace="android:networkSecurityConfig"' to element at AndroidManifest.xml:7:5-138 to override.
I tried the suggested workaround but the error is still here.
What is the correct way to achieve what I want?

I have the same issue.
For react native, i found that it already has react_native_config.xml at project/android/app/src/debug/res/xml/react_native_config.xml
just add your domain in react_native_config.xml example
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">example.com</domain>
<domain includeSubdomains="false">localhost</domain>
<domain includeSubdomains="false">10.0.2.2</domain>
<domain includeSubdomains="false">10.0.3.2</domain>
</domain-config>
</network-security-config>

<application
xmlns:tools="http://schemas.android.com/tools"
tools:replace="android:networkSecurityConfig"
android:networkSecurityConfig="#xml/network_security_config"
android:name=".MainApplication"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="#style/AppTheme">

Related

Cleartext HTTP traffic to ... not permitted

my program takes an URL from the user, so it may make request to any website of the internet.
I'm trying to make this possible, I looked up all the answers about "Android HTTP Cleartext" errors, and made this, but it still doesn't let me connect my test local PHP server, what am I missing here?
<uses-permission android:name="android.permission.INTERNET" />
...
<application
...
android:usesCleartextTraffic="true"
android:networkSecurityConfig="#xml/network_security_config"
tools:ignore="UnusedAttribute"
My security config:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">api.example.com</domain>
</domain-config>
</network-security-config>
Thanks!
Try changing your network_security_config.xml as follows:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true"></base-config>
</network-security-config>

NetworkSecurityConfig: Using Network Security Config from resource "network_security_config" debugBuild: true

Tell me how you can fix it?
AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<application
...
android:networkSecurityConfig="#xml/network_security_config"
android:usesCleartextTraffic="true"
...>
<activity>
...
</activity>
</application>
network_security_config.xml
<network_security_config>
<base-config cleartextTrafficPermitted="true"/>
</network_security_config>
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">secure.example.com</domain>
</domain-config>
</network-security-config>
if you are using this android:networkSecurityConfig then remove android:usesCleartextTraffic="true"
For reference
NetworkSecurityConfig: No Network Security Config specified, using platform default

Android Studio warning " Setting <base-config cleartextTrafficPermitted="true"/> is not recommended."

I'm integrating PayUMoney with my app. For Android versions above 9 cleartextTrafficPermitted="false" by default. So I get the following error:
The webpage at http://180.179.174.15:3000/pgSimulator/axis/redirect
could not be loaded because: net::ERR_CLEARTEXT_NOT_PERMITTED
So in network_security_config.xml, I changed it to true as below:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true"/>
</network-security-config>
And now Android Studio shows:
Setting is not
recommended.
Now is it safe to set it to false? If I don't set it to false. PayUMoney does not work. So what to do now?
Either use
<application
...
android:usesCleartextTraffic="true">
....
</application>
Or set config like below with domain:
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">Your_domain</domain>
</domain-config>
</network-security-config>

Cleartext error when sending to local ip address -- Android 9

We send an HTTP request to a device on a local network (192.168.1.1) in an Android app. The device only accepts HTTP not https requests. It was working until the Android system update yesterday (T837VVRU1BSC3). Now cleartext traffic is rejected.
I have tried the following without success:
android:usesCleartextTraffic="true"
adding android:networkSecurityConfig="#xml/network_security_config" and
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">192.168.1.1</domain>
</domain-config>
</network-security-config>
changing the xml file to:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
These are the only suggested solutions I can find to permit cleartext traffic. Does anyone know of other solutions?
Add the below line in the manifest in the application tag where icon, label, theme is defined
android:usesCleartextTraffic="true"
Add the "android:usesCleartextTraffic="true" in the AndroidManifest.xml is okey
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
android:usesCleartextTraffic="true">

net::ERR CLEARTEXT_NOT_PERMITTED page is shown in my mobile web app for android 9.0 using phonegap

I am creating my web app using phonegap and it works fine but I come to know that it is not working in android 9 pie, it shows web page not found with the below message
net::ERR CLEARTEXT_NOT_PERMITTED
I tried to rectify it by adding the below code in my network-security-config.xml file
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
And also added the below lines in AndroidManifest.xml
<manifest... >
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
android:networkSecurityConfig="#xml/network_security_config"
android:usesCleartextTraffic="true">
</application>
</manifest>
But I do not get it right. Can anyone help me with the solution ? Thanks in advance.
This simple code works for me:
network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
And in AndroidManifest file:
android:networkSecurityConfig="#xml/network_security_config">

Categories

Resources