安装Flutter/Dart包后iOS项目运行失败,报CocoaPods编码错误
Flutter iOS端运行失败问题
刚完成Android Studio、Xcode、CocoaPods及Flutter/Dart SDK的安装,新建Flutter项目能在iOS和Android端正常运行。但安装Flutter/Dart包后,执行flutter run时iOS端运行失败,报错信息如下:
报错信息
Launching lib/main.dart on iPhone 14 Pro Max in debug mode... Running pod install... Error output from CocoaPods: ↳ WARNING: CocoaPods requires your terminal to be using UTF-8 encoding. Consider adding the following to ~/.profile: export LANG=en_US.UTF-8 /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/unicode_normalize/normalize.rb:141:in `normalize': Unicode Normalization not appropriate for ASCII-8BIT (Encoding::CompatibilityError) from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.12.1/lib/cocoapods/config.rb:166:in `unicode_normalize' from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.12.1/lib/cocoapods/config.rb:166:in `installation_root' from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.12.1/lib/cocoapods/config.rb:226:in `podfile_path' from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.12.1/lib/cocoapods/user_interface/error_report.rb:105:in `markdown_podfile' from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.12.1/lib/cocoapods/user_interface/error_report.rb:30:in `report' from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.12.1/lib/cocoapods/command.rb:66:in `report_error' from /Library/Ruby/Gems/2.6.0/gems/claide-1.1.0/lib/claide/command.rb:396:in `handle_exception' from /Library/Ruby/Gems/2.6.0/gems/claide-1.1.0/lib/claide/command.rb:337:in `rescue in run' from /Library/Ruby/Gems/2.6.0/gems/claide-1.1.0/lib/claide/command.rb:324:in `run' from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.12.1/lib/cocoapods/command.rb:52:in `run' from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.12.1/bin/pod:55:in `<top (required)>' from /usr/local/bin/pod:23:in `load' from /usr/local/bin/pod:23:in `<main>' Error running pod install Error launching application on iPhone 14 Pro Max.
flutter doctor -v 输出
memmcol@memmcols-MBP demo % flutter doctor -v [✓] Flutter (Channel stable, 3.10.6, on macOS 13.4.1 22F770820d darwin-x64, locale en-NG) • Flutter version 3.10.6 on channel stable at /Users/memmcol/development/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision f468f3366c (8 days ago), 2023-07-12 15:19:05 -0700 • Engine revision cdbeda788a • Dart version 3.0.6 • DevTools version 2.23.1 [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/memmcol/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 14.3.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 14E300c • CocoaPods version 1.12.1 [✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome) ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable. [✓] Android Studio (version 2022.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694) [✓] Connected device (2 available) • iPhone 14 Pro Max (mobile) • 99935478-7F27-4F63-A005-89ABC3F5B1DA • ios • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator) • macOS (desktop) • macos • darwin-x64 • macOS 13.4.1 22F770820d darwin-x64 [✓] Network resources • All expected network resources are available. ! Doctor found issues in 1 category.
已尝试的无效方案
方案一
- cd ios
- pod cache clean --all
- pod clean
- pod deintegrate
- sudo gem install cocoapods-deintegrate cocoapods-clean
- sudo arch -x86_64 gem install ffi
- arch -x86_64 pod repo update
- arch -x86_64 pod install
方案二
- flutter clean
- rm -Rf ios/Pods
- rm -Rf ios/.symlinks
- rm -Rf ios/Flutter/Flutter.framework
- rm -Rf ios/Flutter/Flutter.podspec
- flutter pub get
- cd ios
- pod install
- arch -x86_64 pod install
- cd ..
- flutter build ios
- flutter run
有效解决办法
从报错信息能看出核心问题是终端UTF-8编码未正确设置,CocoaPods依赖该编码环境运行。按以下步骤操作:
打开终端,编辑你的shell配置文件(zsh用户编辑
~/.zshrc;bash用户编辑~/.bash_profile或~/.profile):nano ~/.zshrc在文件末尾添加两行编码配置:
export LANG=en_US.UTF-8 export LC_ALL=en_US.UTF-8保存并退出nano:按
Ctrl+O回车确认保存,再按Ctrl+X退出。让配置立即生效:
source ~/.zshrc验证编码是否设置成功:
echo $LANG echo $LC_ALL输出均应为
en_US.UTF-8回到Flutter项目目录,重新执行清理和安装:
flutter clean cd ios pod deintegrate pod install cd .. flutter run
额外检查点
如果上述步骤无效,检查你的项目路径是否包含中文、特殊字符(空格以外的符号),CocoaPods对非ASCII路径兼容性较差,建议将项目移到纯英文路径下重试。
内容的提问来源于stack exchange,提问作者abeeb ilias
相关产品推荐
相关产品推荐

