flutter中国镜像如何配置
我想在Flutter开发中使用中国镜像来加速依赖包的下载,但不太清楚具体该怎么配置。请问该如何设置Flutter的中国镜像?需要修改哪些配置文件?有没有详细的步骤说明?另外,使用镜像后会不会影响后续的版本更新或其他功能?
2 回复
在项目根目录的android/build.gradle文件中,将google()和jcenter()替换为阿里云镜像:
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
同时配置Flutter SDK环境变量:
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
更多关于flutter中国镜像如何配置的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
在Flutter中配置中国镜像可以显著提升依赖包下载速度,以下是配置方法:
方法一:设置环境变量(推荐) 在系统环境变量中添加以下两个变量:
Windows:
- 右键“此电脑” → 属性 → 高级系统设置 → 环境变量
- 新建系统变量:
变量名:PUB_HOSTED_URL
变量值:https://pub.flutter-io.cn
变量名:FLUTTER_STORAGE_BASE_URL
变量值:https://storage.flutter-io.cn
macOS/Linux: 在终端执行(永久生效):
echo 'export PUB_HOSTED_URL=https://pub.flutter-io.cn' >> ~/.bash_profile
echo 'export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn' >> ~/.bash_profile
source ~/.bash_profile
方法二:项目级配置
在Flutter项目根目录的android文件夹下新建gradle.properties文件,添加:
systemProp.http.proxyHost=mirrors.cloud.tencent.com
systemProp.http.proxyPort=80
systemProp.https.proxyHost=mirrors.cloud.tencent.com
systemProp.https.proxyPort=80
验证配置: 重启终端后执行:
flutter doctor
观察包下载是否使用镜像地址。
注意事项:
- 镜像服务由社区维护,若遇问题可暂时移除环境变量恢复官方源
- 常见镜像源:
- 上海交大镜像
- 腾讯云镜像
- 阿里云镜像
配置完成后,Flutter SDK和插件的下载速度将得到明显提升。

