Android: 无法解析 com.squareup.okhttp

Android: can not resolve com.squareup.okhttp

我想在我的应用程序中使用 squareup 的 OkhttpClient,所以我将以下代码添加到 build.gradle:

 compile 'com.squareup.okhttp3:okhttp:3.0.1'

但是java还是无法解决:

这里有什么问题?

OkHttpClient has moved 从包 com.squareup.okhttpokhttp3

URLConnection 也支持 has moved 到 okhttp-urlconnection 模块。 所以你需要使用

HttpURLConnection connection = new OkUrlFactory(client).open(url);