无法解析Android Studio 3.2.1中的依赖项

时间:2019-01-14 10:44:03

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

在将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
}

致谢

3 个答案:

答案 0 :(得分:1)

在您的项目级别Gradle中 像我的示例一样更改google()的位置。

__sync_synchronize

答案 1 :(得分:1)

根据this,您需要classpath 'com.android.tools.build:gradle:3.3.0'才能获得配额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" }

也是。

答案 2 :(得分:1)

对我来说,原因是我在禁区工作。因此,存在文件下载被阻止的情况。以及gradle如何无法下载所有依赖项。我只是在开放的Internet连接中运行所有内容,并且一切都像一个魅力。

因此,我遵循了此thread,以允许在受限环境中下载软件包。如果在受限的环境中工作仍不能解决您的问题,请与网络人员联系。