Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

build.gradle dependancies for retrofit and latest version of okhttp

In our application we use retrofit for networking with the following dependancies:

 compile 'com.squareup.retrofit2:retrofit:2.3.0'
 compile 'com.squareup.retrofit2:converter-gson:2.3.0'

Of late we started getting this crash which has been resolved. How then do i fix this within our app? My understanding is that retrofit is built on top of the okHttp library. So does this mean we would have to wait for a new version of retrofit that includes the new okHttp version OR I can manually include the new version of okHttp as a seperate dependancy and end up with:

 compile 'com.squareup.retrofit2:retrofit:2.3.0'
 compile 'com.squareup.retrofit2:converter-gson:2.3.0'
 compile 'com.squareup.okhttp3:okhttp:3.8.1'

Proguard config is (only the retrofit part though)

-dontnote retrofit2.Platform
-dontwarn retrofit2.Platform$Java8
-dontwarn okhttp3.**
-dontwarn retrofit2.**
-dontwarn com.squareup.picasso.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions
-keepclasseswithmembers class * { @retrofit2.http.* <methods>; }
-keepclasseswithmembers interface * { @retrofit2.* <methods>; }
-dontwarn okio.**
like image 460
AndroidNoob Avatar asked Jul 20 '17 10:07

AndroidNoob


1 Answers

Yes you can force new okhttp version by adding compile 'com.squareup.okhttp3:okhttp:3.8.1'

If you run gradlew app:dependencies, you will see this:

releaseCompileClasspath - Resolved configuration for compilation for variant: release
+--- com.squareup.retrofit2:retrofit:2.3.0
|    \--- com.squareup.okhttp3:okhttp:3.8.0 -> 3.8.1
|         \--- com.squareup.okio:okio:1.13.0

It is means, that Retrofit declare dependency okhttp:3.8.0, but Gradle replace it by okhttp:3.8.1

PS: This is applied for situation, when you does not define custom dependency resolution strategy

like image 111
DeKaNszn Avatar answered Nov 15 '22 00:11

DeKaNszn