M1配置Flutter环境及运行项目常见问题解决方法

环境:

2021 iMac M1

Flutter 3.0.5

Android Studio Arctic Fox

配置文件zshrc(M1之后默认类型由bash改成了zshrc)

常见问题及解决方法:

以下报错并非将所有错误都显示出来,只展示了前部分。

  • 没有flutter命令
    解决:确定flutterSDK已配置在zshrc中,使用 source ~/.zshrc来强制当前窗口使用zshrc配置。M1的机型默认不是bash而是zshrc

  • error: could not find included file ‘Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig’ in search paths (in target ‘Runner’)
    解决:xxx.xcconfig文件未生成,需pod install,网络不好情况下请使用恰当的网络pod

  • pod (mach-o file, but is an incompatible architecture (have (arm64), need (x86_6
    解决:sudo arch -x86_64 gem install ffi arch -x86_64 pod install M1以x86模式运行命令 ;或者arch -x86_64 $SHELL运行命令。M1机型是arm架构,而现在大部分mac还是x86架构。

  • CocoaPods could not find compatible versions for pod “xxx“
    解决:AS内搜该插件,检查该插件的最低iOS deployed target是否与Xcode项目最低版本持平。

  • xcode lib/main.dart: Error: Error when reading ‘lib/main.dart’: No such file or di
    解决:target/Flutter/Generated.xcconfig,检查其内的FLUTTER_APPLICATION_PATH=/Users/mac_m1/xxx 是否为flutter启动路径

  • 找不到iOS设备/ Xcode installation is incomplete; full installation is necessary for iOS development
    解决:sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
    sudo xcodebuild -runFirstLaunch (注意Xcode版本号及安装路径,多个Xcode容易存在路径写错问题)

  • 无法运行iOS真机:Exception: CocoaPods not installed or not in valid state.
    解决:open /Applications/Android\ Studio.app (注意AS版本号及安装路径)

猜你喜欢

转载自blog.csdn.net/kicinio/article/details/128713303