Could not resolve com.android.support.constraint:constraint-layout:1.1.3问题的解决

完整log:

ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.3.
Show Details
Affected Modules: app


ERROR: Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.3.
Show Details
Affected Modules: app


ERROR: Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.3.
Show Details
Affected Modules: app

 

问题发生时,我的gradle插件的版本是3.4.1

dependencies {
    classpath 'com.android.tools.build:gradle:3.4.1'
    

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

关于这个问题,网上大体是说,看一下SDK Manger中当前已经安装的constraint-layout的版本,然后依赖这个版本即可。

我的理解还是没法下载constraint:constraint-layout,所以在Project的build.gradle中添加各种maven依赖库,阿里、华为等都不可以使用。

最后想到我的另一个工程可以正常运行,看了下配置,依赖的gradle插件的版本是3.1.2

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
}

然后勾选offline work,让gradle从本地找需要的库,而不是在网上找,问题解决。

Could not resolve com.android.support.constraint:constraint-layout:1.1.3问题的解决_第1张图片

本地的gradle的库保存在C:/Users/liguanlin/.gradle的目录下。

Could not resolve com.android.support.constraint:constraint-layout:1.1.3问题的解决_第2张图片

可以发现我本地有如上的gradle的版本。gradle插件版本和gradle版本的对应关系如下:

插件版本 所需的 Gradle 版本
1.0.0 - 1.1.3 2.2.1 - 2.3
1.2.0 - 1.3.1 2.2.1 - 2.9
1.5.0 2.2.1 - 2.13
2.0.0 - 2.1.2 2.10 - 2.13
2.1.3 - 2.2.3 2.14.1+
2.3.0+ 3.3+
3.0.0+ 4.1+
3.1.0+ 4.4+
3.2.0 - 3.2.1 4.6+
3.3.0 - 3.3.2 4.10.1+
3.4.0+ 5.1.1+

我之前的项目用的是gradle4.4,可以跑起来

新项目配置的插件版本是3.4.1, gradle版本是5.1.1 该版本依赖的库constraint-layout:还未下载到本地,所以会产生问题。

gradle-plugin的相关知识,可以参考https://developer.android.google.cn/studio/releases/gradle-plugin。

你可能感兴趣的:(Android)