Search code examples
flutterxcodedartcocoapods

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


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': 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.

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

Solution

  • 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="" LC_COLLATE="C" LC_CTYPE="C" LC_MESSAGES="C" LC_MONETARY="C" LC_NUMERIC="C" LC_TIME="C" 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. :) Happy coding!