Skip to content

Windows 下 Flutter 换源方法错误 #192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
xrgzs opened this issue Apr 13, 2025 · 1 comment · Fixed by #193
Closed
1 task done

Windows 下 Flutter 换源方法错误 #192

xrgzs opened this issue Apr 13, 2025 · 1 comment · Fixed by #193
Labels
pl_target pl target Windows Windows相关
Milestone

Comments

@xrgzs
Copy link
Contributor

xrgzs commented Apr 13, 2025

你操作了什么?

我运行了 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
@xrgzs xrgzs added the Bug 存在缺陷 label Apr 13, 2025
@ccmywish
Copy link
Contributor

感谢指正 @xrgzs 👍

有兴趣直接修改代码提交PR吗?

@ccmywish ccmywish added this to the v0.2.2 milestone Apr 14, 2025
@ccmywish ccmywish added pl_target pl target Windows Windows相关 and removed Bug 存在缺陷 labels Apr 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pl_target pl target Windows Windows相关
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants