Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrofit 2 on sdk < 21

I used Retrofit library in my android application. My project's minSDK is 16. Now I see that my apps not working on SDK < 21 because of retrofit version. My retrofit version:

implementation 'com.squareup.retrofit2:retrofit:2.6.1'
implementation 'com.squareup.retrofit2:converter-gson:2.6.1'

I tested OkHttp 2 but it is not adapted with my retrofit. What should I do?

like image 512
Behrooz Fard Avatar asked Nov 26 '22 23:11

Behrooz Fard


1 Answers

The problem is that OkHttp3, from version 3.13.0 upped its minimum SDK version to API 21+.

If you just want to do basic HTTP(s) requests and do not care about TLS 1.2, then you can just exclude that specific version and use 3.12.13 which is the last version to support minSDK 9+.

implementation("com.squareup.retrofit2:retrofit:2.9.0") {
    exclude group: "com.squareup.okhttp3"
}

implementation "com.squareup.okhttp3:okhttp:3.12.13"

Add this to your build.gradle file and things should start working. However, from the next version, you should ideally be removing this and up your minSDK level to 21+.

like image 133
Sri Harsha Chilakapati Avatar answered Nov 28 '22 14:11

Sri Harsha Chilakapati