6

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?

Behrooz Fard
  • 536
  • 4
  • 26

2 Answers2

1

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+.

Sri Harsha Chilakapati
  • 11,744
  • 6
  • 50
  • 91
-1

Add these lines in build gradle file:

    // retrofit, gson
    implementation 'com.squareup.okhttp3:logging-interceptor:3.4.2'
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    implementation 'com.squareup.retrofit2:converter-scalars:2.3.0'
    implementation 'com.squareup:otto:1.3.8'
    implementation 'com.google.code.gson:gson:2.8.5'

This is complete package of retrofit

elyar abad
  • 771
  • 1
  • 8
  • 27
bishal
  • 13
  • 5