Showing posts with label IOException. Show all posts
Showing posts with label IOException. Show all posts

Cleartext Http Traffic not Permitted Android 9

Android Studio Error Log: java.io.IOException: Cleartext HTTP traffic to my_IP/domain not permitted

2019-09-06 12:20:29.050 22531-22531/com.geekscompete.gate_isro_cs.ugc_net_preparation E/VolleyError:: ::com.android.volley.NoConnectionError: java.io.IOException: Cleartext HTTP traffic to http://geekscompete.com/ not permitted

Reason for this error:
According to Network security configuration - Opt out of cleartext traffic
Note: The guidance in this section applies only to apps that target Android 8.1 (API level 27) or lower. Starting with Android 9 (API level 28), cleartext support is disabled by default. Network security configuration also suggest to ensure that all connections to your domain are always done over HTTPS to protect sensitive traffic from hostile networks.

You have to create a new file in your xml folder, file named network_security_config.xml.
res/xml/network_security_config.xml:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">yourdomain.com</domain>
        <domain includeSubdomains="true">geekscompete.com</domain>
        <domain includeSubdomains="true">geekscompete.blogspot.com</domain>
    </domain-config>
</network-security-config>

This config will now allow clear traffic to your specified domains after you . Make sure that you have set android:networkSecurityConfig="@xml/network_security_config" in the application tag of your AndroidManifest.xml. The content of your config file should contain all URLs which requests clear traffic without encryption. As shown in below code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.yourappname">
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:name=".MainApplication"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:allowBackup="false"
        android:supportsRtl="true"
        android:networkSecurityConfig="@xml/network_security_config"
        android:theme="@style/AppTheme">
    </application>
</manifest>


Related Articles: 


java.lang.IllegalArgumentException: Stack size becomes negative after instruction

Exception while processing task java.io.IOException: java.lang.IllegalArgumentException: Stack size becomes negative after instruction [23] invokestatic #46 in [com/google/android/gms/internal/ads/zzap.zzf(Ljava/lang/String;)J]
After updating Google Play Services to 15.0.1(latest) from 12.0.1 my release builds stop working.
I come across the above Proguard error after updated the gms library gradle versions as follows:
1 //    compile 'com.google.android.gms:play-services-ads:12.0.1'
    compile 'com.google.android.gms:play-services-ads:15.0.1'

2  //    compile 'com.google.android.gms:play-services-analytics:12.0.1'
    compile 'com.google.android.gms:play-services-analytics:16.0.1'

3   //    compile 'com.google.android.gms:play-services-auth:12.0.1'
    compile 'com.google.android.gms:play-services-auth:15.0.1'

4  //    compile 'com.google.android.gms:play-services-gcm:12.0.1'
    compile 'com.google.android.gms:play-services-gcm:15.0.1'

Solution for above error while generating signed APK is to Add following to your proguard-rules.pro
-keep class com.google.android.gms.internal.** { *; }

Popular Posts