flutter遇到的问题汇总

1. lib/main.dart:1:8: Error: Error when reading '../../../../development/flutter/packages/flutter/lib/material.dart': No such file or directory

出现问题原因: 我更改了flutter的环境变量位置,由原来的~/development/flutter换到~/opt/flutter再次打开flutter项目运行, 报错

解决方案:

  1. 快捷键shift+cmd+f搜索Users/xxx/development/flutter替换成Users/xxx/opt/flutter
  2. 找到项目文件下.dart_tool/package_config.json 打开, 然后搜索Users/xxx/development/flutter替换成Users/xxx/opt/flutter

2. The getter 'addressOf' isn't defined for the class 'GUID'.

解决方案: 终端执行下面语句就可以了

$ flutter clean
$ flutter pub get
$ flutter pub upgrade

参考链接这里

3. undefined local variable or method `continue' for #

   [!] An error occurred while processing the post-install hook of the Podfile.

    undefined local variable or method `continue' for #

    /Users/malgee/opt/flutter/packages/flutter_tools/bin/podhelper.rb:63:in `block (2 levels) in flutter_additional_ios_build_settings'
    /Users/malgee/opt/flutter/packages/flutter_tools/bin/podhelper.rb:62:in `each_child'
    /Users/malgee/opt/flutter/packages/flutter_tools/bin/podhelper.rb:62:in `block in flutter_additional_ios_build_settings'
    /Users/malgee/opt/flutter/packages/flutter_tools/bin/podhelper.rb:51:in `each'
    /Users/malgee/opt/flutter/packages/flutter_tools/bin/podhelper.rb:51:in `flutter_additional_ios_build_settings'
    /Users/malgee/Desktop/Flutter/FlutterDouBan/ios/Podfile:36:in `block (3 levels) in from_ruby'
    /Users/malgee/Desktop/Flutter/FlutterDouBan/ios/Podfile:35:in `each'
    /Users/malgee/Desktop/Flutter/FlutterDouBan/ios/Podfile:35:in `block (2 levels) in from_ruby'
    /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-core-1.11.3/lib/cocoapods-core/podfile.rb:196:in `post_install!'
    /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:945:in `run_podfile_post_install_hook'
    /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:933:in `block in run_podfile_post_install_hooks'
    /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/user_interface.rb:149:in `message'
    /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:932:in `run_podfile_post_install_hooks'
    /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:331:in `block (2 levels) in create_and_save_projects'
    /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer/xcode/pods_project_generator/pods_project_writer.rb:61:in `write!'
    /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:330:in `block in create_and_save_projects'
    /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/user_interface.rb:64:in `section'
    /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:309:in `create_and_save_projects'
    /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:301:in `generate_pods_project'
    /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:180:in `integrate'
    /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:167:in `install!'
    /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/command/install.rb:52:in `run'
    /Users/malgee/.rvm/gems/ruby-2.6.3/gems/claide-1.1.0/lib/claide/command.rb:334:in `run'
    /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/command.rb:52:in `run'
    /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/bin/pod:55:in `'
    /Users/malgee/.rvm/gems/ruby-2.6.3/bin/pod:23:in `load'
    /Users/malgee/.rvm/gems/ruby-2.6.3/bin/pod:23:in `
' /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:947:in `rescue in run_podfile_post_install_hook' /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:944:in `run_podfile_post_install_hook' /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:933:in `block in run_podfile_post_install_hooks' /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/user_interface.rb:149:in `message' /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:932:in `run_podfile_post_install_hooks' /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:331:in `block (2 levels) in create_and_save_projects' /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer/xcode/pods_project_generator/pods_project_writer.rb:61:in `write!' /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:330:in `block in create_and_save_projects' /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/user_interface.rb:64:in `section' /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:309:in `create_and_save_projects' /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:301:in `generate_pods_project' /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:180:in `integrate' /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/installer.rb:167:in `install!' /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/command/install.rb:52:in `run' /Users/malgee/.rvm/gems/ruby-2.6.3/gems/claide-1.1.0/lib/claide/command.rb:334:in `run' /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/lib/cocoapods/command.rb:52:in `run' /Users/malgee/.rvm/rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/gems/cocoapods-1.11.3/bin/pod:55:in `' /Users/malgee/.rvm/gems/ruby-2.6.3/bin/pod:23:in `load' /Users/malgee/.rvm/gems/ruby-2.6.3/bin/pod:23:in `
' Error running pod install Error launching application on iPhone 13.

解决方案: https://github.com/flutter/flutter/issues/104118

进入到下面路径打开podhelper.rb文件, 修改 63 行
/Users/malgee/opt/flutter/packages/flutter_tools/bin/podhelper.rb

 
continue if xcframework_file.start_with?(".") # Hidden file, possibly on external disk. 

改成

next if xcframework_file.start_with?(".") 

4. Error (Xcode): ../../../.pub-cache/hosted/pub.flutter-io.cn/file-6.1.2/lib/src/interface/file.dart:15:16: Error: The method 'File.create' has fewer named arguments than those of overridden method 'File.create'.

file版本比较低, 需要升级, 执行完之后升级到了 6.1.4,
解决方案:

pub upgrade
pub get

5. This app is using a deprecated version of the Android embedding.

This app is using a deprecated version of the Android embedding.
To avoid unexpected runtime failures, or future build failures, try to migrate this app to the V2 embedding.
Take a look at the docs for migrating an app: https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects

解决: 修改路径下的文件内容 android->app->src->main->AndroidManifest.xml

  • 删除这一行
android:name="io.flutter.app.FlutterApplication"
  • 平级位置添加

image.png

6. error: This requires the 'non-nullable' language feature to be enabled.

pubspec.yaml文件修改

从 Flutter 2(和 Dart 2.12)开始,空安全是新的默认值。这意味着通过指定以下 SDK 约束:

environment:
  sdk: '>=2.12.0 <3.0.0'

解决方案来源: Stackoverflow

7.

报错信息

Error (Xcode): Invalid depfile: /Users/xxx/Desktop/Flutter/FlutterProject/github_myDemo/douya/.dart_tool/flutter_build/57ec51b5fb657ca2c2bd8e2da11a3b8a/kernel_snapshot.d

Could not build the application for the simulator.
Error launching application on iPhone 13.

解决方案:

flutter clean
flutter run

8 Android Studio 控制台(Logcat)不输出打印

使用终端运行,可以看到打印输出, 之后换成在用 Android Studio 直接运行就可以打印输出了

flutter run --profile

9 运行卡住 Running Gradle task 'assembleDebug'...

  1. 打开您的flutter项目目录。
  2. 将目录更改为您的flutter项目目录cd android中的android目录
  3. 执行./gradlew clean, 清理 gradle
  4. 再重新构建gradle 执行./gradlew build或者你可以将这两个命令合并使用./gradlew clean build
  5. 现在运行你的flutter项目 gradle第一次运行assembleDebug需要一些时间。

来源:这里

你可能感兴趣的:(flutter遇到的问题汇总)