java Gradle 错误:无法解析 org.jacoco:org.jacoco.agent

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39587945/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 04:29:48  来源:igfitidea点击:

Gradle error: Could not resolve org.jacoco:org.jacoco.agent

javaandroidandroid-gradle-pluginbuild.gradle

提问by Yurii Bulan

FAILURE: Build failed with an exception.

FAILURE:构建失败,出现异常。

  • What went wrong: Could not resolve all dependencies for configuration ':app:androidJacocoAgent'.
  • 出了什么问题:无法解决配置“:app:androidJacocoAgent”的所有依赖项。

Could not resolve org.jacoco:org.jacoco.agent:0.7.5.201505241946. Required by: MYAPP:app:unspecified No cached version of org.jacoco:org.jacoco.agent:0.7.5.201505241946 available for offline mode. No cached version of Blockquote

无法解析 org.jacoco:org.jacoco.agent:0.7.5.201505241946。要求:MYAPP:app:unspecified 没有缓存版本的 org.jacoco:org.jacoco.agent:0.7.5.201505241946 可用于离线模式。没有 Blockquote 的缓存版本

My project's build.gradle looks like this:

我的项目的 build.gradle 看起来像这样:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/ASL2.0'
    }
    defaultConfig {
        applicationId "com.myapp"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 8
        versionName '2.0.6 BETA'
        HymanOptions {
            enabled true
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.2.0'
    compile 'com.android.support:design:24.2.0'
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'io.reactivex:rxandroid:1.0.1'
    compile 'com.squareup.retrofit2:retrofit-adapters:2.1.0'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
    compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
    compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.google.android.gms:play-services-maps:9.4.0'
    compile 'com.google.android.gms:play-services-gcm:9.4.0'
}

回答by Luke Melaia

It looks like some dependency needs org.jacoco:org.jacoco.agent:0.7.5.201505241946as a dependency, but can't find it for some reason. It can be found in the maven repository side so it does exist. Add this line: compile group: 'org.jacoco', name: 'org.jacoco.agent', version: '0.7.5.201505241946'to your dependencies list, so it will look like this:

看起来有些依赖需要org.jacoco:org.jacoco.agent:0.7.5.201505241946作为依赖,但是因为某种原因找不到。它可以在 maven 存储库端找到,所以它确实存在。将此行:添加compile group: 'org.jacoco', name: 'org.jacoco.agent', version: '0.7.5.201505241946'到您的依赖项列表中,使其看起来像这样:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile group: 'org.jacoco', name: 'org.jacoco.agent', version: '0.7.5.201505241946'
    compile 'com.android.support:appcompat-v7:24.2.0'
    compile 'com.android.support:design:24.2.0'
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'io.reactivex:rxandroid:1.0.1'
    compile 'com.squareup.retrofit2:retrofit-adapters:2.1.0'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
    compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
    compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.google.android.gms:play-services-maps:9.4.0'
    compile 'com.google.android.gms:play-services-gcm:9.4.0'
}

This will add the dependency to your project and cut out the middle man so to speak.

这会将依赖项添加到您的项目中,并且可以说减少了中间人。

回答by shtolik

For me it happened because android studio actually entered offline mode somehow. After disabling offline mode (Settings->Build, Execution, Deployment-> Gradle-> Offline work) dependency was successfully retrieved.

对我来说,这是因为 android studio 实际上以某种方式进入了离线模式。禁用离线模式后(设置->构建、执行、部署-> Gradle->离线工作)依赖被成功检索。

回答by 18446744073709551615

I had this problem because I need VPN to build (the jar repository is private), and VPN was not active.

我遇到了这个问题,因为我需要 VPN 来构建(jar 存储库是私有的),而 VPN 未处于活动状态。

回答by Dickson the developer

This might be late to answer but I had the same problem and resolved by disabling offline mode. However, sometime offline mode don't show when you follow these steps Settings (preferences on Mac)->Build, Execution, Deployment-> Gradle-> Offline work. So what you can do instead is click on the Gradle (on right navigation) and choose the network icon (Toggle offline mode) and disable offline mode. I hope it helps!

这可能回答晚了,但我遇到了同样的问题并通过禁用离线模式解决了。但是,当您按照这些步骤操作时,有时不会显示离线模式 Settings (preferences on Mac)->Build, Execution, Deployment-> Gradle-> Offline work。因此,您可以做的是单击 Gradle(在右侧导航中)并选择网络图标(切换离线模式)并禁用离线模式。我希望它有帮助!