Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in configuring network security xml in android

In the android network security docs , it says to create a network_security_config.xml file in res/xml folder.

In order to make an entry in manifest file, it says to make an entry in this way

<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
    <application android:networkSecurityConfig="@xml/network_security_config"
                    ... >
        ...
    </application>
</manifest>

But I am getting the error No resource identifier found for attribute 'networkSecurityConfig' in package 'android'

I also checked for the valid attributes in application tag ( android docs ), there is no attribute as "networksecurityconfig"

like image 486
Netdeamon Avatar asked Jan 30 '17 12:01

Netdeamon


People also ask

What is network security configuration in Android?

The Network Security Configuration feature lets apps customize their network security settings in a safe, declarative configuration file without modifying app code. These settings can be configured for specific domains and for a specific app.

What is cleartext Android?

Cleartext is any transmitted or stored information that is not encrypted or meant to be encrypted. When an app communicates with the server using a cleartext network traffic, such as HTTP, it could raise the risk of eavesdropping and tampering of content. If you are using the https, then no worry about this issue.


2 Answers

You need to set your compileSdkVersion to 24 or higher and set your buildToolsVersion to 24.0.0 or higher.

With regards to the documentation, that's a documentation bug.

like image 198
CommonsWare Avatar answered Oct 08 '22 10:10

CommonsWare


The documentation is fixed, the xml should live inside res/xml which is not in the root but inside android/app:

android/app/src/main/res/xml/network_security_config.xml

From minimumSDK 20 you will need the file and be sure to whitelist localhost and 10.0.2.2 and 10.0.3.2 or you'll have trouble on development

like image 30
wolffan Avatar answered Oct 08 '22 10:10

wolffan