【问题标题】:Unable to resolve dependencies in Android Studio 3.2.1无法解析 Android Studio 3.2.1 中的依赖项
【发布时间】:2019-06-08 08:21:52
【问题描述】:

在将 gradle 更新到 5.1.1 后,我遇到了无法解决依赖关系的错误。我已经在这个thread 和这个one as well 中尝试了所有可能的解决方案。但无法解决我的问题。

这是我的错误日志:

Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0.
Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.3.
Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support:design:28.0.0.
Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support.test:runner:1.0.2.
Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support.test.espresso:espresso-core:3.0.2.
Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0.
Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.3.
Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support:design:28.0.0.
Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0.
Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.3.
Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.android.support:design:28.0.0.
Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0.
Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.3.
Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve com.android.support:design:28.0.0.
Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0.
Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.3.
Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve com.android.support:design:28.0.0.

这是应用级别的build.gradle 文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.project.FirstApplication"
        minSdkVersion 15
        targetSdkVersion 28
        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:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:design:28.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

这是项目的build.gradle

buildscript {

    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.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
  • @Darish 我已经编辑了我的帖子

标签: java android android-studio android-gradle-plugin build.gradle


【解决方案1】:

对我来说,原因是我在禁区内工作。因此阻止了正在下载的文件。还有一些 gradle 无法下载所有依赖项的方式。我只是在开放的互联网连接中运行所有东西,一切都像魅力一样。

所以我按照这个thread 允许在受限环境中下载包。如果您在受限环境中工作,仍然无法解决您的问题,请联系您的网络人员。

【讨论】:

    【解决方案2】:

    你需要classpath 'com.android.tools.build:gradle:3.3.0',根据this for gradle 5.1.1

    我不同意 Deepak 提出的将 google() 放在最后的提示。从历史上看,由于其他问题,我首先需要它。

    另外,您的implementation 'com.android.support:appcompat-v7:28.0.0' 是多余的,因为已经有implementation 'com.android.support:design:28.0.0'

    根据this可以删除

    maven { url "https://maven.google.com" }

    也是。

    【讨论】:

      【解决方案3】:

      在你的项目级 Gradle 像我的例子一样改变 google() 的位置。

      buildscript {
          repositories {
              jcenter()
              maven {
                  url 'https://maven.fabric.io/public'
              }
              maven {
                  url 'https://maven.google.com/'
                  name 'Google'
              }
              google()
          }
          dependencies {
              classpath 'com.android.tools.build:gradle:3.1.2'
              classpath 'com.google.gms:google-services:3.2.1'
              classpath 'io.fabric.tools:gradle:1.25.4'
      
      
              // NOTE: Do not place your application dependencies here; they belong
              // in the individual module build.gradle files
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2019-03-31
        • 1970-01-01
        • 1970-01-01
        • 2013-12-12
        • 2017-05-18
        • 2015-12-19
        • 2018-04-30
        • 1970-01-01
        相关资源
        最近更新 更多