Gradle sync失败:无法解析配置的所有依赖项':app:debugRuntimeClasspath'

时间:2017-12-15 06:40:36

标签: android

我最近将我的Android Studio更新到3.0.1版,我开始了一个空白活动的新项目。一旦gradle sync同步开始(我打开项目后),我会在事件日志中收到一条消息:

Gradle sync failed: Could not resolve all dependencies for configuration ':app:debugRuntimeClasspath'.
                Could not determine artifacts for com.android.support:appcompat-v7:26.1.0
                Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/support/appcompat-v7/26.1.0/appcompat-v7-26.1.0.aar'.
                Could not HEAD 'https://dl.google.com/dl/android/maven2/com/android/support/appcompat-v7/26.1.0/appcompat-v7-26.1.0.aar'.
                Connect to dl.google.com:443 [dl.google.com/216.58.197.46] failed: Connection refused: connect
                Connection refused: connect
                Consult IDE log for more details (Help | Show Log) (3s 878ms)

我从Android SDK管理器重新安装了支持存储库,并将maven添加到依赖项中,但到目前为止还无法解决问题。

build-gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {  
 repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.0.1'

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

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

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

app level build-gradle:

apply plugin: 'com.android.application'

android {
 compileSdkVersion 26
 defaultConfig {
    applicationId "com.example.vishalbisht.test"
    minSdkVersion 15
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner 
 "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 
'proguard-rules.pro'
    }
 }
}

dependencies {
 implementation fileTree(dir: 'libs', include: ['*.jar'])
 implementation 'com.android.support:appcompat-v7:26.1.0'
 implementation 'com.android.support:design:26.1.0'
 implementation 'com.android.support.constraint:constraint-layout:1.0.2'
 testImplementation 'junit:junit:4.12'
 androidTestImplementation 'com.android.support.test:runner:1.0.1'
 androidTestImplementation 'com.android.support.test.espresso:espresso-
 core:3.0.1'
}

3 个答案:

答案 0 :(得分:3)

通过在app level build-gradle中评论以下几行,我能够解决这个问题

   androidTestImplementation 'com.android.support.test:runner:1.0.1'
   androidTestImplementation 'com.android.support.test.espresso:espresso-
   core:3.0.1'

然后它开始工作,不确定这是否是一个可接受的解决方案,但据我所知,我至少可以运行和编译我的代码。

在Android Studio 3.1更新之后,我还没有遇到过这个问题。

答案 1 :(得分:2)

更改此

 android {
 compileSdkVersion 26
 defaultConfig {
    applicationId "com.example.vishalbisht.test"
    minSdkVersion 15
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner 
 "android.support.test.runner.AndroidJUnitRunner"
}

 android {
 compileSdkVersion 26
 buildToolsVersion '26.0.1'
 defaultConfig {
    applicationId "com.example.vishalbisht.test"
    minSdkVersion 15
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner 
 "android.support.test.runner.AndroidJUnitRunner"
}

并使用其中任何一个google() maven { url "https://maven.google.com" }

阅读我之前的回答here

答案 2 :(得分:0)

将您的Gradle和Gradle版本插件升级到最新版本。并将您的项目迁移到androidx。

   classpath 'com.android.tools.build:gradle:3.5.1'

和gradle.wrapper

#Mon Nov 04 15:09:35 IRST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip