无法导入com.squareup.okhttp.OkHttpClient; [英] not able to import com.squareup.okhttp.OkHttpClient;

查看:1867
本文介绍了无法导入com.squareup.okhttp.OkHttpClient;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究android studio并从网上获取一些数据。我尝试使用 OkHttpClient ,并将jar添加到我的项目文件夹中,但仍然无法导入它。

显示无法解析符号okhttp
我尝试了一些解决方案,但无法解决问题。这里是我的 build.gradle文件

  apply plugin:'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion23.0.0

defaultConfig {
applicationId com.example.app
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName1.0
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
}
}


}

依赖关系{
编译fileTree(dir:'libs',include:['* .jar'])
编译'com.android.support:appcompat-v7 :23.0.0'
compile'c​​om.google.android.gms:play-services:8.4.0'
//编译文件('libs / okhttp-3.0.1.jar')
//编译文件('libs / okio-1.6.0.jar')


}


解决方案

Gradle应该有这样一行

  compile'c​​om。 squareup.okhttp3:okhttp:3.0.1'

这就是你如何导入它

  import okhttp3.OkHttpClient; 

由于 OkHttpClient

com.squareup.okhttp okhttp3 p>更多详细信息请参阅此处 here

I am working on android studio and fetching some data from the web. I tried using OkHttpClient and also added jars to my project folder but still i am unable to import it.

It shows can't resolve symbol okhttp. I tried some solution but unable to solve the problem.Here is my build.gradle file

apply plugin: 'com.android.application'
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.0"

    defaultConfig {
        applicationId "com.example.app"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }


}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.0'
    compile 'com.google.android.gms:play-services:8.4.0'
 //   compile files('libs/okhttp-3.0.1.jar')
   // compile files('libs/okio-1.6.0.jar')


}

解决方案

Gradle should have a line like this

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

and this is how you import it

import okhttp3.OkHttpClient;

Because OkHttpClient has been moved from package com.squareup.okhttp to okhttp3 in the last version.

More details are here and here

这篇关于无法导入com.squareup.okhttp.OkHttpClient;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆