Flutter应用在Android Studio中无法运行。

5

我有一个简单的 flutter 应用,其中包含 sqflite 数据库。当我尝试通过 Android Studio 运行应用时,它会给出以下错误:

Launching lib/main.dart on iPhone 12 Pro in debug mode...
Running pod install...
CocoaPods' output:
↳
      CDN: trunk Relative path: CocoaPods-version.yml exists! Returning local because checking is only performed in repo update

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.11.2/lib/cocoapods/config.rb:166:in `unicode_normalize'
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/lib/cocoapods/config.rb:166:in `installation_root'
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/lib/cocoapods/config.rb:226:in `podfile_path'
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/lib/cocoapods/user_interface/error_report.rb:105:in `markdown_podfile'
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/lib/cocoapods/user_interface/error_report.rb:30:in `report'
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/lib/cocoapods/command.rb:66:in `report_error'
        from /Library/Ruby/Gems/2.6.0/gems/claide-1.0.3/lib/claide/command.rb:396:in `handle_exception'
        from /Library/Ruby/Gems/2.6.0/gems/claide-1.0.3/lib/claide/command.rb:337:in `rescue in run'
        from /Library/Ruby/Gems/2.6.0/gems/claide-1.0.3/lib/claide/command.rb:324:in `run'
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/lib/cocoapods/command.rb:52:in `run'
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/bin/pod:55:in `<top (required)>'
        from /usr/local/bin/pod:23:in `load'
        from /usr/local/bin/pod:23:in `<main>'
    /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.11.2/lib/cocoapods/config.rb:166:in `unicode_normalize'
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/lib/cocoapods/config.rb:166:in `installation_root'
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/lib/cocoapods/config.rb:226:in `podfile_path'
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/lib/cocoapods/config.rb:205:in `podfile'
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/lib/cocoapods/command.rb:160:in `verify_podfile_exists!'
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/lib/cocoapods/command/install.rb:46:in `run'
        from /Library/Ruby/Gems/2.6.0/gems/claide-1.0.3/lib/claide/command.rb:334:in `run'
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/lib/cocoapods/command.rb:52:in `run'
        from /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.11.2/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 12 Pro.

当我尝试通过外部终端运行时,它可以正常工作

我已经尝试过运行"export UTF-8",但没有任何反应。

我该如何解决这个问题呢? 希望你能理解我的问题。 谢谢。

2个回答

0

删除 PodfilePodfile.lockPods 文件夹Runner.xcworkspace、ios/Flutter 文件夹中的 Flutter.framwork。

flutter clean

flutter build ios

或者试试这个

rm ios/Podfile
flutter pub upgrade
flutter pub run
cd ios
pod init
pod update
flutter clean && flutter run

但这与外部终端相同,我需要直接从Android Studio运行。 - nirav

0
请先尝试应用这个解决方案,然后再尝试这个。
Make sure brew is installed. If not /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Set shell to zsh curl -L http://install.ohmyz.sh | sh
or, set PATH
eval "$(rbenv init -)"
Install Ruby Version Manager brew update brew install rbenv ruby-build

Install Ruby rbenv install 2.6 # I used my systems default version number because I was not sure if it messes with my OS X system version. rbenv global 2.6 rbenv rehash

Add it to your zsh echo 'eval "$(rbenv init -)"' >> ~/.zshrc source ~/.zshrc

请执行以下步骤:

From xcode -> open preferences 
-> location -> 
Derived Data -> 
move to bin and remove it from Bin as well.

from android studio -> bottom panel -> Terminal -> enter following commands
-> flutter clean 
-> flutter pub get
-> cd ios [if not navigated to ios folder in flutter project]
-> pod install
-> pod update

now, run the app from android studio.

you will be able to run now.

在执行 pod installpod update 命令时,我收到了与上述相同的警告/错误提示。 - nirav
请检查我的更新答案。 - Hardik Mehta

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接