Flutter配置Gradle镜像,解决国内下载慢问题
未优化之前
程序运行时会卡在Running Gradle task 'assembleDebug'...
如下提示信息
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
Launching lib\main.dart on sdk gphone64 x86 64 in debug mode...
Running Gradle task 'assembleDebug'...
此时Gradle正在下载gradle构建工具以及相关依赖库,由于官方gradle默认配置的依赖下载服务器处于国外,国内用户访问非常缓慢,常常一个依赖下载就要花半天时间,好在国内有阿里、清华等镜像源,我们可以配置镜像代理加快依赖的下载
优化步骤
修改build.gradle
进入项目目录的android/build.gradle
,修改为如下,注意不要注释掉google()
和mavenCentral()
,因为部分依赖可能镜像源没有,gradle
找不到的话会报错
buildscript {
ext.kotlin_version = '1.7.10'
repositories {
maven { url 'https://maven.aliyun.com/repository/public/' }
maven { url 'https://maven.aliyun.com/repository/spring/'}
maven { url 'https://maven.aliyun.com/repository/google/'}
maven { url 'https://maven.aliyun.com/repository/gradle-plugin/'}
maven { url 'https://maven.aliyun.com/repository/spring-plugin/'}
maven { url 'https://maven.aliyun.com/repository/grails-core/'}
maven { url 'https://maven.aliyun.com/repository/apache-snapshots/'}
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.0'
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/spring/'}
maven { url 'https://maven.aliyun.com/repository/google/'}
maven { url 'https://maven.aliyun.com/repository/gradle-plugin/'}
maven { url 'https://maven.aliyun.com/repository/spring-plugin/'}
maven { url 'https://maven.aliyun.com/repository/grails-core/'}
maven { url 'https://maven.aliyun.com/repository/apache-snapshots/'}
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
修改gradle-wrapper.properties
进入android/wrapper/gradle-wrapper.properties
文件文章来源:https://www.toymoban.com/news/detail-752350.html
distributionUrl
的值用镜像源替代,需要注意的是后面的gradle版本需要和替换镜像源前的gradle
版本一致文章来源地址https://www.toymoban.com/news/detail-752350.html
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-7.5-all.zip
到了这里,关于Flutter配置Gradle镜像,解决国内下载慢问题的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!