新版AS Could not find com.android.support.constraint:constraint-layout问题 时间: 2020-12-30 19:45 分类: JAVA ####前言 首先,我不是搞`android`开发的,只是随便玩玩。 `github`上下载了代码用`AS4.1.1`打开`build`的时候报了这个错误: > Could not find com.android.support.constraint:constraint-layout 网上一搜,虽有解决办法,但都是低版本的`AS`。 ####解决 在新版本中`SDK Manager`里面根本找不到对应的包了。 其实官网就有解决方案: > https://developer.android.com/topic/libraries/support-library/setup.html 1.在项目的 build.gradle 文件中添加 Google 的 Maven 代码库。 ``` allprojects { repositories { google() // If you're using a version of Gradle lower than 4.1, you must // instead use: // gradle 版本低于4.1 使用下面的方法 // maven { // url 'https://maven.google.com' // } } } ``` 2.对于要在其中使用支持库的每个模块,请在模块的 build.gradle 文件的 dependencies 块中添加相应库。 所有的支持库在这里可以找到,你也可以自行搜索: https://mvnrepository.com/artifact/com.android.support 例如:需要引入`constraint-layout` 之前的代码是: ``` compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7' ``` 改成: ``` compile group: 'com.android.support.constraint', name: 'constraint-layout', version: '1.1.3' ``` 标签: 无