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

Failed to resolve com.android.support:support-annotations 26.0.1

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 Manager Android SDK Build Tools 26.0.1 安装,我也有最新版本的 Android 支持。

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()
    }
}

即使使用 Android Studio 3.0.+,我也必须在下面添加这个(不仅仅是 google() 像@CommonsWare 推荐的那样),以传递错误

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

}

我通过在项目级别 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
}