OkHttp 3 and HttpURLConnection

10,924

I tried to depend on com.squareup.okhttp:okhttp-urlconnection:3.0.0 but that doesn't exist.

The names were updated as well. It is now

com.squareup.okhttp3:okhttp-urlconnection:3.0.0

NOte the okhttp3 instead of okhttp.

For more information on the reasoning behind this, see Jake Wharton (the author)'s blog post on Java Interoperability Policy for Major Version Updates here:

https://jakewharton.com/java-interoperability-policy-for-major-version-updates/

See jCenter.

Share:
10,924
BoD
Author by

BoD

Please see my personal home page http://JRAF.org or my Google+ public profile at http://JRAF.org/+

Updated on June 07, 2022

Comments

  • BoD
    BoD about 2 years

    I am a bit confused about how to upgrade OkHttp to v3.0.0 while keeping our code that uses HttpURLConnection. Our current dependencies are:

    compile 'com.squareup.okhttp:okhttp:2.7.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.7.0'
    

    The changelog states:

    The Apache HTTP client and HttpURLConnection APIs are deprecated. They continue to work as they always have, but we're moving everything to the new OkHttp 3 API. The okhttp-apache and okhttp-urlconnection modules should be only be used to accelerate a transition to OkHttp's request/response API. These deprecated modules will be dropped in an upcoming OkHttp 3.x release.

    Unfortunately it is not clear to me what "we're moving everything to the new OkHttp 3 API" means.

    I tried to depend on com.squareup.okhttp:okhttp-urlconnection:3.0.0 but that doesn't exist.

    Should I keep com.squareup.okhttp:okhttp-urlconnection:2.7.0 and upgrade only com.squareup.okhttp:okhttp to 3.0.0? Or does this sentence mean that depending only on com.squareup.okhttp:okhttp should work?

  • BoD
    BoD over 8 years
    Doh! The funny thing is I saw this, but then my brain decided to black it out ;) Thanks!
  • BoD
    BoD over 8 years
    Except now I have this weird problem: com.android.dex.DexException: Multiple dex files define Lokhttp3/Address; edit.. which I fixed like this, but this is weird: compile ('com.squareup.okhttp3:okhttp-urlconnection:3.0.0') { exclude group: 'com.squareup.okhttp3' }
  • Tim
    Tim over 8 years
    @BoD new problem -> new question
  • BoD
    BoD over 8 years
    I ended up opening a ticket here about this second problem: github.com/square/okhttp/issues/2243
  • atreat
    atreat about 8 years
    Using com.squareup.okhttp3:okhttp-urlconnection:3.0.1 seems to fix the github issue.