【问题标题】:Gradle sync failed: Could not resolve all dependencies for configuration ':app:debugRuntimeClasspath'Gradle 同步失败:无法解析配置“:app:debugRuntimeClasspath”的所有依赖项
【发布时间】:2017-12-15 06:40:36
【问题描述】:

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

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 添加到依赖项,但到目前为止无法解决问题。

构建等级:

// 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
}

应用级 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'
}

【问题讨论】:

  • 与问题分享您的Build-Gradle
  • 发布你的应用级别build.gradle文件
  • @Nilu 希望这会有所帮助。
  • @VishalBisht 用于测试用例 buildToolsVersion "27.0.0"
  • 你的错误提示 Connect to dl.google.com:443 [dl.google.com/216.58.197.46] failed: Connection refused: connect 尝试使用稳定的 Internet 连接进行同步

标签: android


【解决方案1】:

我可以通过在应用程序级 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 更新之后,我也没有遇到过这个问题。

【讨论】:

  • Vishal,它有效!您介意解释一下为什么我们需要注释掉这两行吗?谢谢。
  • @userIndulgeInDChord 我当时的理解是这两个库没有更新为与改进的 android 版本 3.0.1 的构建过程兼容。您在哪个版本的 Android Studio 上遇到问题?
【解决方案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

【讨论】:

  • 什么都不做
【解决方案3】:

最有可能的解决方案如下

  1. 在您的应用 build.gradle 中检查目标版本

    targetSdkVersion 30

  2. 去SDK管理器查看你是否有相同的SDK,应该是30作为API级别

【讨论】:

    【解决方案4】:

    将您的 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
    

    【讨论】:

      猜你喜欢
      • 2021-12-04
      • 1970-01-01
      • 1970-01-01
      • 2014-10-04
      • 2016-03-17
      • 2016-10-09
      • 1970-01-01
      • 1970-01-01
      • 2022-12-14
      相关资源
      最近更新 更多