1

The old recipe for using Retrofit with OkHttp was simply to add it as a dependency like this:

compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
compile 'com.squareup.okhttp:okhttp:2.0.0'

I.e. adding line 2 and 3 will make Retrofit utilize OkHttp as the communication framework.

Since OkHttp became a part of the Android SDK from v4.4 and up, is adding the two lines now obsolete? Will having just line 1 as dependency yield the exact same runtime result on Android 4.4 and up?

How can I verify this? I tried to put a breakpoint in my code on a 4.4 device to see what kind of HTTP library is used by Retrofit, but it's difficult to know which field to trill down to. See image below

Debug drill-down

P.S: Please leave Retrofit2 out of this, I know things have changed :)

Community
  • 1
  • 1
Nilzor
  • 18,082
  • 22
  • 100
  • 167

1 Answers1

2

Since OkHttp became a part of the Android SDK from v4.4 and up, is adding the two lines now obsolete?

No, you still need to include OkHttp dependency same way you did so far, because OkHttp is used by the platform, but not exposed as part of public API for apps to use.

See this tweet thread: https://twitter.com/JakeWharton/status/482563299511250944

Stefan F ‏@frostymarvelous  12 Aug 2015
@JakeWharton @justin is there a way to reference it
without a gradle dependency as its part of the core?

Jake Wharton ‏@JakeWharton  12 Aug 2015
@frostymarvelous @justin No. It's completely hidden from the
public API and repacked inside http://com.android  package name.
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141