Flutter 解决编译器在链接过程中找不到 `FlutterMacOS` 框架

8 min read
 fvm flutter run  -d macos

Launching lib/main.dart on macOS in debug mode...
Building macOS application...                                   
ld: warning: Could not find or use auto-linked framework 'FlutterMacOS'
Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_FlutterAppDelegate", referenced from:
      type metadata for flutter_demo.AppDelegate in AppDelegate.o
  "_OBJC_CLASS_$_FlutterViewController", referenced from:
      objc-class-ref in MainFlutterWindow.o
  "_OBJC_METACLASS_$_FlutterAppDelegate", referenced from:
      _OBJC_METACLASS_$__TtC12flutter_demo11AppDelegate in AppDelegate.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
** BUILD FAILED **

Exception: Build process failed

这个错误是由于编译器在链接过程中找不到 FlutterMacOS 框架,这可能是由于缓存问题或者框架路径问题导致的。您可以尝试以下方法解决这个问题:

  1. 清理项目缓存:
    在项目根目录下运行以下命令:

    fvm flutter clean
    
  2. 删除 iosmacos 目录:
    从项目根目录中删除 iosmacos 文件夹。

  3. 重新创建 iosmacos 目录:
    运行以下命令:

    fvm flutter create .
    

    这将在项目根目录下重新创建 iosmacos 文件夹。

  4. 再次运行应用程序:

    fvm flutter run -d macos
    

如果问题仍然存在,您可以尝试更新 Flutter 到最新版本,运行以下命令:

fvm flutter upgrade

完成更新后,请重复上述步骤 1-4。希望这可以解决您的问题。