错误:(28,13)未能解析:com.squareup.okhttp3:okhttp:3.2.0



我在安卓工作室遇到问题。

我已经从以下链接添加了okhttp的.jar文件:https://github.com/square/okhttp到我的android工作室上的libs目录。当我试图在build.gradle(模块:应用程序)中的依赖项中添加这一行:compile"com.squareup.okhttp3:okhttp:3.2.0"时,在尝试同步它之后,我得到了错误28,13。事实上,经过研究,我发现我不能在依赖关系中编译任何东西并同步它。记住,我已经检查了我的"android SDK构建工具"是否已安装。

hear是我在build.gradle(应用程序)目录中的全部代码:

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 files('libs/okhttp-3.2.0.jar')的行。

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

它可能会帮助别人。在我的案例中,在将com.squareup.okhttp3更新到最新版本后,我在AndroidJava libaray中出现了此错误。然后我将Java版本更新到1.8,这解决了我的问题。

targetCompatibility = '1.8'
sourceCompatibility = '1.8'

您应该更改build.gradle(app):使用

implementation 'com.squareup.okhttp3:okhttp:3.10.0'

而不是

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

或者按照这里提到的指南进行操作。

只需将依赖项替换为下面的依赖项,它们肯定会起作用。(100%)。如果将来这个问题再次出现,请转到https://square.github.io/okhttp/并使用最新的更新您的依赖关系

    //define any required ok http without version
   implementation("com.squareup.okhttp3:okhttp")
   implementation("com.squareup.okhttp3:logging-interceptor")
   //define a BOM and its version
   implementation(platform("com.squareup.okhttp3:okhttp-bom:4.9.0"))

只需删除compile files('libs/okhttp-3.2.0.jar')

我通过如下编辑我的build.gradle解决了我的问题:

apply plugin: 'com.android.library'
android {
    compileSdkVersion 24
    buildToolsVersion '25.0.0'
    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 23
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),         
    'proguard-rules.txt'
        }
    }
    lintOptions {
        abortOnError false
    }
}
dependencies {
    compile project(':library')
    //compile('com.squareup.okhttp3:okhttp:+') {
    //    exclude group: 'org.json'
    //}
    //replaced as below:
    compile 'com.squareup.okhttp3:okhttp:3.9.1'
}

在app.gradle 中检查您的代码

apply plugin: 'com.android.application'

repositories {jcenter()}

将okhttp编译为脱机模式,然后在setting->gradle中取消选中脱机模式。并重试

您将不需要此

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

相反,你需要

implementation 'com.squareup.okhttp3:okhttp:4.9.0'

截至2020年9月30日检查https://square.github.io/okhttp/用于文档

最新更新