【问题标题】:Error:(28, 13) Failed to resolve: com.squareup.okhttp3:okhttp:3.2.0错误:(28, 13) 无法解决:com.squareup.okhttp3:okhttp:3.2.0
【发布时间】:2016-07-16 03:00:42
【问题描述】:

我的 android studio 有问题。

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

听到的是我在 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'
}

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

非常感谢:)

【问题讨论】:

    标签: android gradle android-gradle-plugin okhttp


    【解决方案1】:

    要么你的互联网很糟糕,你不能从 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 文件。

    【讨论】:

      【解决方案2】:

      它可能对某人有所帮助。在我的情况下,将com.squareup.okhttp3 更新到最新版本后,我在 Android Java libaray 中遇到了这个错误。然后我将 Java 版本更新到 1.8,这解决了我的问题。

      targetCompatibility = '1.8'
      sourceCompatibility = '1.8'
      

      【讨论】:

      • 你救了我几个小时!
      【解决方案3】:

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

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

      而不是

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

      或者只是按照提到的指南here

      【讨论】:

        【解决方案4】:

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

        【讨论】:

          【解决方案5】:

          我通过如下编辑 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'
          }
          

          【讨论】:

          • 这个答案可以解释为什么它解决了这个问题
          【解决方案6】:

          在 app.gradle 中检查你的代码

          apply plugin: 'com.android.application'

          repositories { jcenter()}

          让你的编译okhttp到离线模式,接下来你在设置-> gradle中取消选中离线模式。然后再试一次

          【讨论】:

            【解决方案7】:

            只需用以下依赖项替换依赖项,它们肯定会工作。(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"))
            

            【讨论】:

              【解决方案8】:

              你不需要这个

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

              你需要

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

              截至今天 2020 年 9 月 30 日 检查https://square.github.io/okhttp/ 以获取文档

              【讨论】:

                猜你喜欢
                • 2017-05-10
                • 1970-01-01
                • 1970-01-01
                • 2019-09-10
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2017-03-19
                • 2016-02-01
                相关资源
                最近更新 更多