3

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?

  • Use this: ... – Kabir Aug 26 '19 at 07:12
  • @Kabir I tried that, but it does not work : CLEARTEXT communication to 192.168.1.61 not permitted by network security policy –  Aug 26 '19 at 07:15
  • Ok, I was unaware of an existing config file for react native https://stackoverflow.com/a/55827042/15186 Now this is working fine –  Aug 26 '19 at 08:21

2 Answers2

3

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>
-2
<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">
Akshay I
  • 3,675
  • 1
  • 34
  • 57