Flutter 项目在我向其安装 Dart/Flutter 包时在 iOS 上运行失败。

huangapple go评论61阅读模式
英文:

Flutter project failed to run on iOS when I install dart/flutter package to it

问题

I just installed Android Studio, Xcode, Cocoapods, and Flutter/Dart SDK. When I create a new Flutter project, it runs fine on both iOS and Android. However, when I install a Dart/Flutter package to my project, I receive the error message below.

Below is the error message:

在 iPhone 14 Pro Max 上以调试模式启动 lib/main.dart...
运行 pod install...
来自 CocoaPods 的错误输出:

警告: CocoaPods 需要终端使用 UTF-8 编码。考虑将以下内容添加到 ~/.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

'

运行 pod install 时发生错误
在 iPhone 14 Pro Max 上启动应用程序时出错。

以下是来自 flutter doctor -v 的信息:

memmcol@memmcols-MBP demo % flutter doctor -v
[✓] Flutter(通道:稳定,3.10.6,macOS 13.4.1 22F770820d darwin-x64,区域设置 en-NG)
• Flutter 版本 3.10.6,通道稳定,位于 /Users/memmcol/development/flutter
• 上游存储库 https://github.com/flutter/flutter.git
• 框架修订 f468f3366c(8 天前),2023-07-12 15:19:05 -0700
• 引擎修订 cdbeda788a
• Dart 版本 3.0.6
• DevTools 版本 2.23.1

[✓] Android 工具链 - 为 Android 设备开发(Android SDK 版本 34.0.0)
• Android SDK 位于 /Users/memmcol/Library/Android/sdk
• 平台 android-34,构建工具 34.0.0
• Java 二进制文件位于:/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java 版本 OpenJDK Runtime Environment(构建 17.0.6+0-17.0.6b802.4-9586694)
• 所有 Android 许可证均已接受。

[✓] Xcode - 为 iOS 和 macOS 开发(Xcode 14.3.1)
• Xcode 位于 /Applications/Xcode.app/Contents/Developer
• 构建 14E300c
• CocoaPods 版本 1.12.1

[✗] Chrome - 为 Web 开发(无法在 /Applications/Google Chrome.app/Contents/MacOS/Google Chrome 找到 Chrome 可执行文件)
! 找不到 Chrome。尝试将 CHROME_EXECUTABLE 设置为 Chrome 可执行文件。

[✓] Android Studio(版本 2022.2)
• Android Studio 位于 /Applications/Android Studio.app/Contents
• 可以从以下位置安装 Flutter 插件:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• 可以从以下位置安装 Dart 插件:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java 版本 OpenJDK Runtime Environment(构建 17.0.6+0-17.0.6b802.4-9586694)

[✓] 已连接的设备(2 台可用)
• iPhone 14 Pro Max(手机)• 99935478-7F27-4F63-A005-89ABC3F5B1DA• ios• com.apple.CoreSimulator.SimRuntime.iOS-16-4(模拟器)
• macOS(桌面)• macos• darwin-x64• macOS 13.4.1 22F770820d darwin-x64

[✓] 网络资源
• 所有预期的网络资源均可用。

! 在 1 个类别中,医生发现了问题。

我在终端上运行了以下命令:

flutter run。我期望我的代码在 iOS 上执行,但出现了与此问题相关的错误消息。

以下是我尝试过的在线解决方案,但它们对我没有起作用。

解决方案一

  1. cd ios
  2. pod cache clean --all
  3. pod clean
  4. pod deintegrate
  5. sudo gem install cocoapods-deintegrate
英文:

I just install android studio, Xcode, cocoapod and flutter/Dart SDK. When I create a new flutter project it run fine on both iOS and android. If I install a dart/flutter package to my project I got the error message below.

Below is the error message

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&#39;: 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&#39;
	from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.12.1/lib/cocoapods/config.rb:166:in `installation_root&#39;
	from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.12.1/lib/cocoapods/config.rb:226:in `podfile_path&#39;
	from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.12.1/lib/cocoapods/user_interface/error_report.rb:105:in `markdown_podfile&#39;
	from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.12.1/lib/cocoapods/user_interface/error_report.rb:30:in `report&#39;
	from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.12.1/lib/cocoapods/command.rb:66:in `report_error&#39;
	from /Library/Ruby/Gems/2.6.0/gems/claide-1.1.0/lib/claide/command.rb:396:in `handle_exception&#39;
	from /Library/Ruby/Gems/2.6.0/gems/claide-1.1.0/lib/claide/command.rb:337:in `rescue in run&#39;
	from /Library/Ruby/Gems/2.6.0/gems/claide-1.1.0/lib/claide/command.rb:324:in `run&#39;
	from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.12.1/lib/cocoapods/command.rb:52:in `run&#39;
	from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.12.1/bin/pod:55:in `&lt;top (required)&gt;&#39;
	from /usr/local/bin/pod:23:in `load&#39;
	from /usr/local/bin/pod:23:in `&lt;main&gt;&#39;

Error running pod install
Error launching application on iPhone 14 Pro Max.

Below is the information from 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.

I run the command below on my terminal

flutter run. I am expecting my code to execute on iOS but it failed with error message tag to this question.

Below are some of the solutions online that I have tried but they are not working for me

Solution One

  1. cd ios
  2. pod cache clean --all
  3. pod clean
  4. pod deintegrate
  5. sudo gem install cocoapods-deintegrate cocoapods-clean
  6. sudo arch -x86_64 gem install ffi
  7. arch -x86_64 pod repo update
  8. arch -x86_64 pod install.

Solution two

  1. flutter clean
  2. rm -Rf ios/Pods
  3. rm -Rf ios/.symlinks
  4. rm -Rf ios/Flutter/Flutter.framework
  5. rm -Rf ios/Flutter/Flutter.podspec
  6. flutter pub get
  7. cd ios
  8. pod install
  9. arch -x86_64 pod install
  10. cd ..
  11. flutter build ios
  12. flutter run

答案1

得分: 1

以下是翻译好的部分:

  1. 打开你的Mac电脑上的命令终端。

  2. 导航到你的项目根文件夹或在你的Android Studio中打开终端。

  3. 输入 locale

你将会得到以下响应:
LANG=&quot;&quot;
LC_COLLATE=&quot;C&quot;
LC_CTYPE=&quot;C&quot;
LC_MESSAGES=&quot;C&quot;
LC_MONETARY=&quot;C&quot;
LC_NUMERIC=&quot;C&quot;
LC_TIME=&quot;C&quot;
LC_ALL=

  1. 通过输入以下命令将上述响应转换为 en_US.UTF-8:
    $open ~/.zshrc

  2. 复制并粘贴 en_US.UTF-8 编码到其中。
    export LANG=en_US.UTF-8
    export LANGUAGE=en_US.UTF-8
    export LC_ALL=en_US.UTF-8

  3. 按住 Command + s(保存 .zshrc 文件),然后关闭它。

  4. 再次输入 locale 命令以验证你的更改。

  5. 运行你的代码 flutter runFlutter 项目在我向其安装 Dart/Flutter 包时在 iOS 上运行失败。 祝编码愉快!

英文:

The Solution to the Question above

  1. Open command terminal on your Mac PC.

  2. Navigate to your project root folder or Open terminal in your android studio.

  3. Type locale.

You will get the response
LANG=&quot;&quot;
LC_COLLATE=&quot;C&quot;
LC_CTYPE=&quot;C&quot;
LC_MESSAGES=&quot;C&quot;
LC_MONETARY=&quot;C&quot;
LC_NUMERIC=&quot;C&quot;
LC_TIME=&quot;C&quot;
LC_ALL=

  1. Convert the response above to en_US.UTF-8 by typing the command
    $open ~/.zshrc

  2. Copy and paste the en_US.UTF-8 encoding to it.
    export LANG=en_US.UTF-8
    export LANGUAGE=en_US.UTF-8
    export LC_ALL=en_US.UTF-8

  3. Hold Command + s (to save the .zshrc file) then after close it

  4. Type locale command again to verify your changes.

  5. Run your code flutter run. Flutter 项目在我向其安装 Dart/Flutter 包时在 iOS 上运行失败。 Happy coding!

huangapple
  • 本文由 发表于 2023年7月20日 18:13:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76728839.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定