How to add Android Network Security Config for API less than 24

Zeeshan picture Zeeshan · Oct 7, 2018 · Viewed 10.7k times · Source

Facebook Audience Network states that.

In the Audience Network Android SDK, we use 127.0.0.1 (localhost) as a caching proxy to cache media files in the SDK. Since Android P, cleartext traffic (unencrypted HTTP) will be blocked by default, which will affect the functionality of media caching of the SDK and could affect user experience and ads revenue.

Now if I try to add this line android:networkSecurityConfig="@xml/network_security_config" in my AndroidManifest I am getting warning that attribute networkSecurityConfig is used in API 24 and higher as my app supports minSdkVersion 15 .

How should I add the android:networkSecurityConfig so that it won't be impacting API less than 24

Answer

CommonsWare picture CommonsWare · Oct 7, 2018

It works that way by default. Older devices will not recognize android:networkSecurityConfig, since it did not exist prior to API Level 24 (Android 7.0).