I'm implementing the Retrofit library into an Android Studio project. Then my goal is calling an external API call from my Android app. Now I implemented Retrofit in my project (using the Kotlin language) without sync/compile errors.
When I run my app from the Android Studio emulator and I call a sample API, I obtain the following error:
javax.ssl.SSLHandshakeException: Chain validation failed
I think I'm having some certificate issue, but I don't know how fix it.
I'm implementing the Retrofit library into an Android Studio project. Then my goal is calling an external API call from my Android app. Now I implemented Retrofit in my project (using the Kotlin language) without sync/compile errors.
When I run my app from the Android Studio emulator and I call a sample API, I obtain the following error:
javax.ssl.SSLHandshakeException: Chain validation failed
I think I'm having some certificate issue, but I don't know how fix it.
Share Improve this question edited Nov 28, 2024 at 13:44 gre_gor 6,72811 gold badges76 silver badges90 bronze badges asked Nov 28, 2024 at 10:05 TinoTino 13 bronze badges 3- 1 Hey, try searching your answers here stackoverflow/a/53297674/17552167 , or else try to cold boot the emulator if you are using it. Or try to check if the API which you are calling is getting called on postman or chrome. If not then you need to fix the URL. Also, if nothing works try to provide your code and also try to change the version of dependency version. – Vishal Shah Commented Nov 28, 2024 at 11:52
- I searched in stackoverflow/a/53297674/17552167, I restarted the emulator, the API is ok because from Postman it works fine, but nothing helps... – Tino Commented Nov 28, 2024 at 16:09
- Please provide enough code so others can better understand or reproduce the problem. – melvio Commented Nov 28, 2024 at 17:51
1 Answer
Reset to default 0I resolved in this way:
- In my API now I use http instead of https
- I created the resource file: res/xml/network_security_config.xml, with:
<?xml version="1.0" encoding="utf-8"?> <network-security-config> <domain-config cleartextTrafficPermitted="true"> <domain includeSubdomains="true">api.example</domain> </domain-config> </network-security-config>
- I edited my AndroidManifest.xml:
<application android:networkSecurityConfig="@xml/network_security_config" ... </application>
Now it works!