问题一:Conflict with dependency 'com.android.support:support-annotations
解决方法:build.gradle中添加:
android {
...
}
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:27.1.1'
}
dependencies {
...
}
问题二:Failed to resolve support-annotations:
解决:
在项目的Project的build.gradle中maven仓库添里面,下面两个仓库地址,任意添加其中之一即可:
allprojects {
repositories {
......
maven { url "https://maven.google.com"}//需要添加的仓库地址
maven { url "https://dl.google.com/dl/android/maven2/"}//需要添加的仓库地址
}
}
问题三:Google仓库
allprojects {
repositories {
//注意一:Google仓库要放在前边
//方式一:
//google()
//Gradle 4.0 and later
//Android Studio 3.0 and later
//Gradle plugin for android 3.0 and later
//所以推荐以下mavenGoogle,作用一样
//方式二:
maven { url 'https://maven.google.com' }
//尽量使用mavenGoogle仓库
//方式三:(国内强烈推荐这种)
maven { url "https://dl.google.com/dl/android/maven2/"}//需要添加的仓库地址
jcenter()
}
...
}
Android Studio Gradle无法获取pom文件
在Project的build.gradle里的allprojects里添加
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
并点击 Gradle—>设置—>Android Studio,勾选 Enable embedded Maven repository
gradle配置国内镜像Enable embedded Maven repository
参考:
Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.1.2/gradle-3
Android Studio在构建项目时会拉取gradle资源,而goole和jcenter在国内的网络环境并不好用,容易产生connect timeout等错误。
因此将地址修改成阿里云的国内镜像。
Enable embedded Maven repository
buildscript {
repositories {
//国内maven库镜像(阿里云)
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven{ url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0-alpha13'
}
}
allprojects {
repositories {
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
maven{ url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
仓库名称 | 代理源地址 | 使用地址 |
---|---|---|
central | https://repo1.maven.org/maven2/ | https://maven.aliyun.com/repository/central 或 https://maven.aliyun.com/nexus/content/repositories/central |
jcenter | http://jcenter.bintray.com/ | https://maven.aliyun.com/repository/jcenter 或 https://maven.aliyun.com/nexus/content/repositories/jcenter |
public | central仓和jcenter仓的聚合仓 | https://maven.aliyun.com/repository/public 或https://maven.aliyun.com/nexus/content/groups/public |
https://maven.google.com/ | https://maven.aliyun.com/repository/google 或 https://maven.aliyun.com/nexus/content/repositories/google |
参考:阿里云公共代理库