其他
Android Studio中gradle版本是否升级的方案(选其一)
1.适合于Android Studio中gradle版本未升级的情况(避免报错的首选方案)
参考文章
Android Studio gradle无法编译App的完美解决方法
(1).build.gradle配置
buildscript {
repositories {
//ADD START
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin' }
//ADD END
google()
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
}
}
allprojects {
repositories {
//ADD START
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin' }
//ADD END
google()
jcenter()
maven {
url "https://jitpack.io"
}
maven {
url 'https://maven.google.com/'
name 'Google'
}
maven { url "https://jitpack.io" }
......
mavenCentral()
}
}
(2).C:\Users\LENOVO\.gradle\init.gradle配置
allprojects{
repositories {
def MY_ALIYUN_REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public'
def MY_ALIYUN_JCENTER_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
all { ArtifactRepository repo ->
if(repo instanceof MavenArtifactRepository){
def url = repo.url.toString()
if (url.startsWith('https://repo1.maven.org/maven2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $MY_ALIYUN_REPOSITORY_URL."
remove repo
}
if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $MY_ALIYUN_JCENTER_URL."
remove repo
}
}
}
maven {
url MY_ALIYUN_REPOSITORY_URL
url MY_ALIYUN_JCENTER_URL
}
}
}
2.适合于Android Studio中gradle版本升级的情况(gradle升级可能jdk版本也需升级)
参考文章
Android Studio中gradle版本升级报gradle的仓库地址不安全警告
(1).build.gradle配置
buildscript {
repositories {
//ADD START
maven {
allowInsecureProtocol = true
url 'http://maven.aliyun.com/nexus/content/groups/public/'
}
maven {
allowInsecureProtocol = true
url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
}
maven {
allowInsecureProtocol = true
url 'http://maven.aliyun.com/nexus/content/repositories/google'
}
maven {
allowInsecureProtocol = true
url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin'
}
//ADD END
google()
mavenCentral()
maven { url 'https://maven.google.com' }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.0'
}
}
allprojects {
repositories {
//ADD START
maven {
allowInsecureProtocol = true
url 'http://maven.aliyun.com/nexus/content/groups/public/'
}
maven {
allowInsecureProtocol = true
url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
}
maven {
allowInsecureProtocol = true
url 'http://maven.aliyun.com/nexus/content/repositories/google'
}
maven {
allowInsecureProtocol = true
url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin'
}
//ADD END
google()
mavenCentral()
maven {
url "https://jitpack.io"
}
maven { url 'https://maven.google.com' }
jcenter()
maven { url 'https://dl.google.com/dl/android/maven2' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
(2).C:\Users\LENOVO\.gradle\init.gradle配置
allprojects{
repositories {
def MY_ALIYUN_REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public'
def MY_ALIYUN_JCENTER_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
all { ArtifactRepository repo ->
if(repo instanceof MavenArtifactRepository){
def url = repo.url.toString()
if (url.startsWith('https://repo1.maven.org/maven2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $MY_ALIYUN_REPOSITORY_URL."
remove repo
}
if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $MY_ALIYUN_JCENTER_URL."
remove repo
}
}
}
maven {
allowInsecureProtocol = true
url MY_ALIYUN_REPOSITORY_URL
url MY_ALIYUN_JCENTER_URL
}
}
}