android - 错误 :(28, 13) 无法解析 : com. squareup.okhttp3 :okhttp:3. 2.0

标签 android gradle android-gradle-plugin okhttp

我有一个关于 android studio 的问题。

我已经从这个链接添加了 okhttp 的 .jar 文件: https://github.com/square/okhttp 到我的 android studio 上的 libs 目录。当我尝试添加这一行时:在 build.gradle(Module:app) 的依赖项中编译 'com.squareup.okhttp3:okhttp:3.2.0',在尝试同步它之后我得到错误 28、13。实际上之后研究我发现我无法编译依赖项中的任何内容并同步它记住我已经检查了我的“android SDK构建工具”已安装。

听到的是我在 build.gradle(app) 目录中的全部代码:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

 defaultConfig {
        applicationId "com.example.kasra.stormy"
        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'], )
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile files('libs/okhttp-3.2.0.jar')
    compile 'com.squareup.okhttp3:okhttp:3.2.0'
}

如果有人帮助我解决这个问题,我将非常高兴和感激。

非常感谢:)

最佳答案

要么您的互联网状况不佳,您无法从 JCenter 下载该文件,要么您的 gradle 文件中缺少一个 repositories 部分。

apply plugin: 'com.android.application'

repositories {
    jcenter()
}

此外,如果您要使用 gradle 而不是 JAR 文件进行编译,请删除文件 libs/okhttp-3.2.0.jar 并删除显示 compile 的行文件('libs/okhttp-3.2.0.jar')

还值得一提的是,您不需要以 compile files('libs/> 开头的任何行,因为 compile fileTree(dir: 'libs', include: ['* .jar'], ) 已经在 libs/ 文件夹中包含所有 JAR 文件。

关于android - 错误 :(28, 13) 无法解析 : com. squareup.okhttp3 :okhttp:3. 2.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36269340/

相关文章:

java - 从alertDialog内的onClickListener访问全局变量

gradle - buildscript 和 build.gradle 中的 allprojects 有什么区别?

java - 如何将使用ant构建的特定android项目转换为gradle?

android - 无法解决 : com. android.support :appcompat-v7:27. +(依赖错误)

android - 在设备或桌面上用于谷歌播放的二维码重定向

android - 如何使用 ionic 3 中的特定联系人从其他应用程序打开 Whatsapp 应用程序?

android - 错误 : Your cpu does not support required features(vt-x or svm) on AMD CPU under Windows

Gradle - 使用 ReplaceTokens 时更改开始/结束 token

Android Gradle 构建 : renaming the apk

android - Android Studio-执行任务失败:app:dexDebug