MacOS 下 flutter run 遇到牆的問題
Mac 下面 flutter run 時遇到 “Download Failed” 錯誤
最近調研 flutter,甚是大愛。
雖然 flutter 非常友好提供了針對中國使用者的映象(Flutter-in-China" target="_blank" rel="nofollow,noindex">Using Flutter in China · flutter/flutter Wiki · GitHub
),解決了一些不可說的難題,但偶爾還是會遇到類似的問題。比如我今天就遇到了,在 VS Code 除錯編譯的時候,遇到 “Download Failed” 的問題。Could not resolve all files for configuration ':image_picker:lintClassPath'.
具體原因是Connect to d29vzk4ow07wi7.cloudfront.net:443 [d29vzk4ow07wi7.cloudfront.net/13.33.69.104, d29vzk4ow07wi7.cloudfront.net/13.33.69.3, d29vzk4ow07wi7.cloudfront.net/13.33.69.38, d29vzk4ow07wi7.cloudfront.net/13.33.69.111] failed: Read timed out
。
原來是碰上了牆外面的老朋友,CDN 服務商 cloudflare 的域名。
中間還是比較曲折,最後解決的辦法是用proxychain4 解決問題。
brew install proxychain-ng sed -i '.bak' 's@^\(socks4.*\)@#\1@g' /usr/local/etc/proxychain.conf echo -e "socks5\t127.0.0.1 1080" >> /usr/local/etc/proxychain.proxy proxychain4 curl ip.gs
等等,好像不對,IP 是本市的。
$ proxychains4 curl ip.gs [proxychains] config file found: /usr/local/etc/proxychains.conf [proxychains] preloading /usr/local/Cellar/proxychains-ng/4.13/lib/libproxychains4.dylib Current IP / 當前 IP: 118.XXX.XXX.XXX ISP / 運營商:ChinaTelecom City / 城市: Chengdu Sichuan Country / 國家: China IP.GS is now IP.SB, please visit https://ip.sb/ for more information. / IP.GS 已更改為 IP.SB ,請訪問 https://ip.sb/ 獲取更詳細 IP 資訊! Please join Telegram group https://t.me/sbfans if you have any issues. / 如有問題,請加入 Telegram 群 https://t.me/sbfans /\_/\ =( °w° )= )(// (__ __)//
哪裡不對?
原來 MacOS X 10.11 以後的版本,還需要禁用 SIP,proxychain 才能正常工作。因為它會修改可執行檔案本身,而位於/usr/bin
下面的 curl 並不能被修改。見這裡——Proxychains 是不是不支援 10.11 了? - V2EX
。
我不想禁用 SIP。安全方面,我還是比較強迫症的。所以用了另外一種方式,就是把可執行檔案,從受系統保護的目錄裡面移出來。
cd /Volumes/RamDisk cp /usr/bin/curl ./ proxychains4 ./curl ip.gs
這下終於行了。
$ proxychains4 ./curl ip.gs [proxychains] config file found: /usr/local/etc/proxychains.conf [proxychains] preloading /usr/local/Cellar/proxychains-ng/4.13/lib/libproxychains4.dylib Current IP / 當前 IP: XXX.XX.XXX.XX ISP / 運營商:xxxxx City / 城市: Osaka Osaka Country / 國家: Japan IP.GS is now IP.SB, please visit https://ip.sb/ for more information. / IP.GS 已更改為 IP.SB ,請訪問 https://ip.sb/ 獲取更詳細 IP 資訊! Please join Telegram group https://t.me/sbfans if you have any issues. / 如有問題,請加入 Telegram 群 https://t.me/sbfans /\_/\ =( °w° )= )(// (__ __)//
用在 flutter 上面試試看。
$ proxychains4 flutter run [proxychains] config file found: /usr/local/etc/proxychains.conf [proxychains] preloading /usr/local/Cellar/proxychains-ng/4.13/lib/libproxychains4.dylib Launching lib/main.dart on BLN AL10 in debug mode... Initializing gradle...0.8s Resolving dependencies...0.8s Running 'gradlew assembleDebug'... FAILURE: Build failed with an exception. * What went wrong: Could not resolve all files for configuration ':image_picker:lintClassPath'. ............ BUILD FAILED in 2m 3s 123.9s Gradle build failed: 1
還是不行?
考慮到上面 curl 遇到的問題,確認 flutter 可執行檔案許可權和路徑沒問題,試試用絕對路徑。
$ proxychains4 ~/workspace/flutter_development/flutter/bin/flutter run [proxychains] config file found: /usr/local/etc/proxychains.conf [proxychains] preloading /usr/local/Cellar/proxychains-ng/4.13/lib/libproxychains4.dylib Launching lib/main.dart on BLN AL10 in debug mode... Initializing gradle...0.8s Resolving dependencies...0.8s Running 'gradlew assembleDebug'...11.8s Built build/app/outputs/apk/debug/app-debug.apk. Installing build/app/outputs/apk/app.apk...3.8s ^C
歐耶!終於成了。
PS:^C 是我終止了 flutter build 的過程。
看得出來,proxychains 通過獨特的方式來讓 command 程式走代理。雖然不是很方便,但總歸解決了問題。還是值得點贊。