无法解决 com.android.support:support-annotations 26.0.1

27
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    testCompile 'junit:junit:4.12'

    // ButterKnife
    compile 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

    // Parse SDK
    compile 'com.parse:parse-android:1.16.0'
}

这是我的应用 gradle 依赖关系。我不知道该怎么解决它。我已经尝试从 SDK 管理器安装 Android SDK Build Tools 26.0.1,并且我也拥有最新版本的 Android support。


可能是重复的问题:无法解析:com.android.support:appcompat-v7:26.0.0 - ישו אוהב אותך
4个回答

67

所有当前版本的 Google 库都存放在 Google 的 Maven 仓库(maven.google.com)中,而不是旧的支持离线仓库。

在您的项目级别的 build.gradle 文件中,请确保 allprojects 闭包如下所示:

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

或者,在Android Studio 3.0及以上版本中,可以像这样:

allprojects {
    repositories {
        jcenter()
        google()
    }
}

@hackingforgirls:请编辑您的问题,并完整发布build.gradle文件(项目级别和模块级别的文件)。 - CommonsWare
3
我的错,我已经在 buildscript 中替换了它,而不是在 allprojects{} 中。现在它可以正常工作了,谢谢! - ghita
希望我2小时前就看到了你的帖子。 - peterkodermac

4
即使使用 Android Studio 3.0.+,我仍需要添加以下内容(不仅仅是像 @CommonsWare 建议的 google()),才能通过错误。
allprojects {
repositories {
    jcenter()
    maven {
        url "https://maven.google.com"
    }
}

}


1
我通过在项目级别的build.gradle文件中添加以下内容来解决了这个问题。
buildscript {

    repositories {
        jcenter()
        google()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'


    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
       jcenter()
       maven {
             url 'https://maven.google.com'
          }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

0

我遇到了这个错误:

ERROR: Failed to resolve: support-annotations

修复它,打开gradle.properties文件并添加

android.enableJetifier=true
#this line must be too:
android.useAndroidX=true

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接