Skip to content

Windows 下 Flutter 换源方法错误 #192

@xrgzs

Description

@xrgzs

你操作了什么?

我运行了 chsrc set flutter

发生了什么?

写入了 PowerShell Profile,而不是设置用户环境变量

if (xy_on_windows)
{
w = xy_strjoin (3, "$env:FLUTTER_STORAGE_BASE_URL = \"", source.url, "\"\n");
if (xy_file_exist (xy_win_powershell_profile))
chsrc_append_to_file (w, xy_win_powershell_profile);
if (xy_file_exist (xy_win_powershellv5_profile))
chsrc_append_to_file (w, xy_win_powershellv5_profile);
}

本应该怎么样?

Windows 下应该设置用户级别的环境变量,使其对所有程序永久生效,如:

[System.Environment]::SetEnvironmentVariable('PUB_HOSTED_URL', 'https://pub.flutter-io.cn', 'User')
[System.Environment]::SetEnvironmentVariable('FLUTTER_STORAGE_BASE_URL', 'https://storage.flutter-io.cn', 'User')

这里使用了PowerShell 调用 System.Environment 类 实现,可以用类似的方法修改环境

chsrc 版本

v0.2.0-2025/03/14

你使用的是哪个操作系统?

Windows

OS 版本 / OS 发行版

Microsoft Windows [Version 10.0.19045.5608]

Log 输出

❯ chsrc set flutter
[chsrc 测速] 测速中

  x 上游默认源 URL未知,邀您参与贡献!
  - 上海交通大学致远镜像站 ... 39.95 MByte/s
  - 清华大学开源软件镜像站 ... 47.56 MByte/s
  - 南京大学开源镜像站 ... 42.63 MByte/s

最快镜像站: 清华大学开源软件镜像站
选中镜像站: TUNA (tuna)
--------------------------------
[chsrc 写入] C:\Users\Xiaoran\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
--------------------------------
chsrc: 全自动换源完成, 感谢镜像提供方: 清华大学开源软件镜像站

❯ cat C:\Users\Xiaoran\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
...
$env:FLUTTER_STORAGE_BASE_URL = "https://mirrors.tuna.tsinghua.edu.cn/git/flutter"

防止重复问题

  • 我已在项目的 GitHub 和 Gitee 两个仓库分别搜索过类似的 issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions