最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

kotlin - Implementing Retrofit on Android Studio - Stack Overflow

programmeradmin2浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 0

I resolved in this way:

  1. In my API now I use http instead of https
  2. 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>
  3. I edited my AndroidManifest.xml: <application android:networkSecurityConfig="@xml/network_security_config" ... </application>

Now it works!

发布评论

评论列表(0)

  1. 暂无评论