找不到模块“audio_session”

Geo*_*lex 17 ios flutter apple-m1

我尝试在带有 M1 芯片的新 Mac 上构建现有的 flutter 项目。\n由于缺少 audio_session 模块,我遇到以下错误。

\n
Launching lib/main.dart on iPhone 12 in debug mode...\nRunning Xcode build...                                                  \n \xe2\x94\x94\xe2\x94\x80Compiling, linking and signing...                        340ms\nXcode build done.                                            4.7s\nFailed to build iOS app\nError output from Xcode build:\n\xe2\x86\xb3\n    objc[7636]: Class AMSupportURLConnectionDelegate is implemented in both ?? (0x1f2fe0188) and ?? (0x117e8c2b8). One of the two will be used. Which one is undefined.\n    objc[7636]: Class AMSupportURLSession is implemented in both ?? (0x1f2fe01d8) and ?? (0x117e8c308). One of the two will be used. Which one is undefined.\n    ** BUILD FAILED **\n\n\nXcode's output:\n\xe2\x86\xb3\n    /Users/user/Projects/myproject/ios/Runner/GeneratedPluginRegistrant.m:10:9: fatal error: module 'audio_session' not found\n    @import audio_session;\n     ~~~~~~~^~~~~~~~~~~~~\n    1 error generated.\n    note: Using new build system\n    note: Building targets in parallel\n    note: Planning build\n    note: Constructing build description\n\nCould not build the application for the simulator.\nError launching application on iPhone 12.\n
Run Code Online (Sandbox Code Playgroud)\n

有什么想法吗?

\n

小智 16

你应该

1. 在 xcode 中打开“Runner.xcworkspace”,而不是“Runner.xcodeproj”

2. 一切顺利


Geo*_*lex 7

最后找到了解决办法。

\n

不知何故,如果我进入我的 flutter 项目的 iOS 文件夹并输入 \'pod init; pod install\' 生成了一个基本的 Podfile(意味着它仅指定了平台)。

\n

我在某个地方发现了一个帖子,建议删除 iOS 文件夹中有关 pod 的所有内容,并在项目中运行 flutter run。在项目文件夹中运行“flutter run”(也集成了“pod install”),生成了一个非常详细的 Podfile,但这次我遇到了另一个与平台有关的错误(如下所列)。

\n
Error output from CocoaPods:\n\xe2\x86\xb3\n\n    [!] Automatically assigning platform `iOS` with version `12.0` on target\n    `Runner` because no platform was specified. Please specify a platform for\n    this target in your Podfile. See\n    `https://guides.cocoapods.org/syntax/podfile.html#platform`.\n\nError: To set up CocoaPods for ARM macOS, run:\n  arch -x86_64 sudo gem install ffi\n
Run Code Online (Sandbox Code Playgroud)\n

我尝试按照建议运行上面显示的命令,但出现了同样的错误。

\n

然后,我在这里找到了Running Cocoapods on Apple Silicon (M1) 的答案,该答案与官方文档https://github.com/flutter/flutter/wiki/Developing-with-Flutter-on-Apple-Silicon类似。

\n

即便如此,堆栈溢出的答案对我来说并没有直接起作用,直到我按照以下步骤操作:

\n
    \n
  1. 打开取景器 -> 实用程序
  2. \n
  3. 右键单击终端 -> 获取信息
  4. \n
  5. 选中“用 Rosetta 打开”
  6. \n
  7. 打开一个新终端并输入“gem uninstall cocoapods”
  8. \n
  9. sudo gem 安装 cocoapods
  10. \n
  11. gem 卸载 ffi
  12. \n
  13. arch -x86_64 sudo gem install ffi
  14. \n
\n

我希望这对其他人有用。

\n