前言:
几年前的项目,因为是一个人维护,自己编译运行都没有啥大问题,某天清除 .gradle下的cache,发现依赖包都找不到了,是因为jcenter跑路了,项目很多依赖库都下载不了。
最省力解决办法:引用阿里云镜像
解决方案
注释jcenter(),引入 mavenCentral(),和阿里云镜像
// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply from: "config.gradle"
buildscript {
ext.kotlin_version = '1.3.61'
repositories {
google()
mavenCentral()
maven { url 'https://maven.aliyun.com/repository/public/' }
mavenLocal()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.1"
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.tencent.bugly:symtabfileuploader:latest.release'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
maven { url 'https://jitpack.io' }
mavenCentral()
maven {url 'http://developer.huawei.com/repo/'}
maven { url 'https://maven.aliyun.com/repository/public/' }
maven { url 'https://maven.aliyun.com/repository/spring/'}
mavenLocal()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
其他坑,如果你发现某些包还是下载不了,去阿里云镜像网站搜索,找到相关最近的版本
还有坑,因为版本不一样了,要进行充分测试,笔者就遇到因为版本不一样方法实现都完全不一样的情况。
flutter项目
在项目\android\build.gradle 修改
buildscript {
ext.kotlin_version = '1.6.10'
repositories {
maven { url 'https://maven.aliyun.com/repository/public' }//jcenter
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }//gradle-plugin
maven { url 'https://maven.aliyun.com/repository/central' }//central
maven { url 'https://maven.aliyun.com/repository/google' }//google
// google()
// mavenCentral()
// jcenter()
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
maven { url 'https://maven.aliyun.com/repository/public' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
maven { url 'https://maven.aliyun.com/repository/central' }
maven { url 'https://maven.aliyun.com/repository/google' }
// google()
// mavenCentral()
// jcenter()
maven { url 'https://jitpack.io' }
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}