软件环境
Flutter 3.19.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 300451adae (2 weeks ago) • 2024-03-27 21:54:07 -0500
Engine • revision e76c956498
Tools • Dart 3.3.3 • DevTools 2.31.1
解决方法
需要修改项目中两个文件:
- gradle/wrapper/gradle-wrapper.properties
- build.gradle (注意:不是 app/build.gradle)
分别修改这两个文件内的 distributionUrl 路径和仓库地址。
修改 gradle/wrapper/gradle-wrapper.properties
将 distributionUrl=https\://services.gradle.org/distributions/gradle-x.x.x-all.zip
修改为 distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-x.x.x-all.zip
。
也就是将 gradle url 的部分路径 https\://services.gradle.org/distributions/
修改为 https\://mirrors.cloud.tencent.com/gradle/
。
以 gradle-7.6.3-all.zip 为例,distributionUrl 修改后的结果如下:
properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
#distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-7.6.3-all.zip
修改 build.gradle
为 repositories
添加阿里仓库:
properties
maven{ url 'https://maven.aliyun.com/repository/google'}
maven{ url 'https://maven.aliyun.com/repository/gradle-plugin'}
maven{ url 'https://maven.aliyun.com/repository/public'}
maven{ url 'https://maven.aliyun.com/repository/jcenter'}
修改后的结果:
properties
allprojects {
repositories {
maven{ url 'https://maven.aliyun.com/repository/google'}
maven{ url 'https://maven.aliyun.com/repository/gradle-plugin'}
maven{ url 'https://maven.aliyun.com/repository/public'}
maven{ url 'https://maven.aliyun.com/repository/jcenter'}
google()
mavenCentral()
}
}
参考文章
https://blog.csdn.net/afunx/article/details/129913028
结束语
本文如有偏颇,恳请斧正。