M1 上的 Flutter:从 Windows 移动到 Mac 后 GoogleMapsBase 和 Flutter.h 未发现错误

Ste*_*ail 5 ios visual-studio-code flutter apple-m1

我已经在我的 Windows 机器上开发 flutter 应用程序有一段时间了,最​​近切换到带有 M1 芯片的 mac mini。该应用程序使用谷歌地图,但当我尝试在 iOS 设备上运行它时,出现以下错误:

\n
Launching lib/main.dart on iPhone 13 Pro Max in debug mode...\nXcode build done.                                           72.1s\nFailed to build iOS app\nError output from Xcode build:\n\xe2\x86\xb3\n    --- xcodebuild: WARNING: Using the first of multiple matching destinations:\n    { platform:iOS Simulator, id:dvtdevice-DVTiOSDeviceSimulatorPlaceholder-iphonesimulator:placeholder, name:Any iOS Simulator Device }\n    { platform:iOS Simulator, id:1BBC3B77-3A9D-4F09-892A-34C7059C2430, OS:15.0, name:iPad (9th generation) }\n    { platform:iOS Simulator, id:BD58EEBD-CC57-418D-B33A-B381EB89E4BE, OS:15.0, name:iPad Air (4th generation) }\n    { platform:iOS Simulator, id:01C2C865-7ED0-4B1E-B391-6546DE9FA12B, OS:15.0, name:iPad Pro (9.7-inch) }\n    { platform:iOS Simulator, id:C0F1BFE8-AC98-487F-8AD2-7A7821D0B1BF, OS:15.0, name:iPad Pro (11-inch) (3rd generation) }\n    { platform:iOS Simulator, id:A9E3236E-DC77-44FD-A18E-8F0326A8D1B1, OS:15.0, name:iPad Pro (12.9-inch) (5th generation) }\n    { platform:iOS Simulator, id:FC86621E-900F-4D94-B709-592D19CCF5C1, OS:15.0, name:iPad mini (6th generation) }\n    { platform:iOS Simulator, id:DF9C52D5-29AE-4048-9EC4-D801ABED90AF, OS:15.0, name:iPhone 8 }\n    { platform:iOS Simulator, id:905D86FA-A373-4DC5-8761-9F20D9573F7E, OS:15.0, name:iPhone 8 Plus }\n    { platform:iOS Simulator, id:FF07BF67-7EB0-4050-98F5-90937B55C083, OS:15.0, name:iPhone 11 }\n    { platform:iOS Simulator, id:1ADD94F5-AFA9-489A-933B-7A01C29A1F80, OS:15.0, name:iPhone 11 Pro }\n    { platform:iOS Simulator, id:F5120FD7-77DE-4BE7-AE09-075A7D08DE80, OS:15.0, name:iPhone 11 Pro Max }\n    { platform:iOS Simulator, id:3198F3B5-25EC-41F9-8A0E-801F17325095, OS:15.0, name:iPhone 12 }\n    { platform:iOS Simulator, id:5BABC83A-DB25-4040-AB2E-65DFC204D8E2, OS:15.0, name:iPhone 12 Pro }\n    { platform:iOS Simulator, id:63451408-2F20-4B65-8E05-570CAA3AAA97, OS:15.0, name:iPhone 12 Pro Max }\n    { platform:iOS Simulator, id:54E2E527-C85D-47F5-ADDE-BA4CF861BE9A, OS:15.0, name:iPhone 12 mini }\n    { platform:iOS Simulator, id:ADD48A2B-3DF4-432E-8561-D566DB2E6FB4, OS:15.0, name:iPhone 13 }\n    { platform:iOS Simulator, id:91162948-B850-494D-A496-E73DBCBC89B4, OS:15.0, name:iPhone 13 Pro }\n    { platform:iOS Simulator, id:9EA1FC3C-1D81-4B6A-8E03-16D634FD64A7, OS:15.0, name:iPhone 13 Pro Max }\n    { platform:iOS Simulator, id:01F0486F-D6B3-4BFF-88AD-5D151293F6A9, OS:15.0, name:iPhone 13 mini }\n    { platform:iOS Simulator, id:BA8A8DF2-519A-4AD1-BED3-F4BCC0DAD591, OS:15.0, name:iPhone SE (2nd generation) }\n    { platform:iOS Simulator, id:7322D286-C468-4FE7-9B82-929CB072CA59, OS:15.0, name:iPod touch (7th generation) }\n    { platform:macOS, arch:arm64, variant:Designed for [iPad,iPhone], id:00008103-001148C13679001E }\n    { platform:iOS, id:dvtdevice-DVTiPhonePlaceholder-iphoneos:placeholder, name:Any iOS Device }\n    ** BUILD FAILED **\nXcode's output:\n\xe2\x86\xb3\n    ld: building for iOS Simulator, but linking in object file built for iOS, file '/Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/ios/Pods/GoogleMaps/Base/Frameworks/GoogleMapsBase.framework/GoogleMapsBase' for architecture arm64\n    clang: error: linker command failed with exit code 1 (use -v to see invocation)\n    note: Using new build system\n    note: Planning\n    note: Build preparation complete\n    note: Building targets in parallel\n    note: Removed stale file '/Users/steliospapamichail/Library/Developer/Xcode/DerivedData/Runner-czjbhkfeqllyfpfkhbtzrnpkcvgk/Build/Intermediates.noindex/Runner.build/Debug-iphonesimulator/Runner.build/Script-BAB43F53538FCAAA1B752783.sh'\n    note: Removed stale file '/Users/steliospapamichail/Library/Developer/Xcode/DerivedData/Runner-czjbhkfeqllyfpfkhbtzrnpkcvgk/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/PromisesObjC.build/Script-023FA270521F1C5E3ED8F5839885EEA7.sh'\n    note: Removed stale file '/Users/steliospapamichail/Library/Developer/Xcode/DerivedData/Runner-czjbhkfeqllyfpfkhbtzrnpkcvgk/Build/Products/Debug-iphonesimulator/google_maps_flutter/google_maps_flutter.framework'\n    /Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 15.0.99. (in target 'leveldb-library' from project 'Pods')\n    /Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 15.0.99. (in target 'FMDB' from project 'Pods')\nCould not build the application for the simulator.\nError launching application on iPhone 13 Pro Max.\nExited (sigterm)\n
Run Code Online (Sandbox Code Playgroud)\n

该错误是否意味着我安装的谷歌地图与我的 M1 芯片不兼容?如果是这样的话,我该怎么做才能绕过它?

\n

更新:尝试了下面评论者添加的链接中提出的解决方案后,我收到了一个关于 googlemaps.h 的错误,我过去也遇到过。这是日志:

\n
Launching lib/main.dart on iPhone 13 Pro Max in debug mode...\nXcode build done.                                           11.3s\nFailed to build iOS app\nError output from Xcode build:\n\xe2\x86\xb3\n    --- xcodebuild: WARNING: Using the first of multiple matching destinations:\n    { platform:iOS Simulator, id:dvtdevice-DVTiOSDeviceSimulatorPlaceholder-iphonesimulator:placeholder, name:Any iOS Simulator Device }\n    { platform:iOS Simulator, id:1BBC3B77-3A9D-4F09-892A-34C7059C2430, OS:15.0, name:iPad (9th generation) }\n    { platform:iOS Simulator, id:BD58EEBD-CC57-418D-B33A-B381EB89E4BE, OS:15.0, name:iPad Air (4th generation) }\n    { platform:iOS Simulator, id:01C2C865-7ED0-4B1E-B391-6546DE9FA12B, OS:15.0, name:iPad Pro (9.7-inch) }\n    { platform:iOS Simulator, id:C0F1BFE8-AC98-487F-8AD2-7A7821D0B1BF, OS:15.0, name:iPad Pro (11-inch) (3rd generation) }\n    { platform:iOS Simulator, id:A9E3236E-DC77-44FD-A18E-8F0326A8D1B1, OS:15.0, name:iPad Pro (12.9-inch) (5th generation) }\n    { platform:iOS Simulator, id:FC86621E-900F-4D94-B709-592D19CCF5C1, OS:15.0, name:iPad mini (6th generation) }\n    { platform:iOS Simulator, id:DF9C52D5-29AE-4048-9EC4-D801ABED90AF, OS:15.0, name:iPhone 8 }\n    { platform:iOS Simulator, id:905D86FA-A373-4DC5-8761-9F20D9573F7E, OS:15.0, name:iPhone 8 Plus }\n    { platform:iOS Simulator, id:FF07BF67-7EB0-4050-98F5-90937B55C083, OS:15.0, name:iPhone 11 }\n    { platform:iOS Simulator, id:1ADD94F5-AFA9-489A-933B-7A01C29A1F80, OS:15.0, name:iPhone 11 Pro }\n    { platform:iOS Simulator, id:F5120FD7-77DE-4BE7-AE09-075A7D08DE80, OS:15.0, name:iPhone 11 Pro Max }\n    { platform:iOS Simulator, id:3198F3B5-25EC-41F9-8A0E-801F17325095, OS:15.0, name:iPhone 12 }\n    { platform:iOS Simulator, id:5BABC83A-DB25-4040-AB2E-65DFC204D8E2, OS:15.0, name:iPhone 12 Pro }\n    { platform:iOS Simulator, id:63451408-2F20-4B65-8E05-570CAA3AAA97, OS:15.0, name:iPhone 12 Pro Max }\n    { platform:iOS Simulator, id:54E2E527-C85D-47F5-ADDE-BA4CF861BE9A, OS:15.0, name:iPhone 12 mini }\n    { platform:iOS Simulator, id:ADD48A2B-3DF4-432E-8561-D566DB2E6FB4, OS:15.0, name:iPhone 13 }\n    { platform:iOS Simulator, id:91162948-B850-494D-A496-E73DBCBC89B4, OS:15.0, name:iPhone 13 Pro }\n    { platform:iOS Simulator, id:9EA1FC3C-1D81-4B6A-8E03-16D634FD64A7, OS:15.0, name:iPhone 13 Pro Max }\n    { platform:iOS Simulator, id:01F0486F-D6B3-4BFF-88AD-5D151293F6A9, OS:15.0, name:iPhone 13 mini }\n    { platform:iOS Simulator, id:BA8A8DF2-519A-4AD1-BED3-F4BCC0DAD591, OS:15.0, name:iPhone SE (2nd generation) }\n    { platform:iOS Simulator, id:7322D286-C468-4FE7-9B82-929CB072CA59, OS:15.0, name:iPod touch (7th generation) }\n    { platform:macOS, arch:arm64, variant:Designed for [iPad,iPhone], id:00008103-001148C13679001E }\n    { platform:iOS, id:dvtdevice-DVTiPhonePlaceholder-iphoneos:placeholder, name:Any iOS Device }\n    ** BUILD FAILED **\nXcode's output:\n\xe2\x86\xb3\nIn file included from /Users/steliospapamichail/development/flutter/.pub-cache/hosted/pub.dartlang.org/google_maps_flutter-2.0.11/ios/Classes/JsonConversions.m:5:\n/Users/steliospapamichail/development/flutter/.pub-cache/hosted/pub.dartlang.org/google_maps_flutter-2.0.11/ios/Classes/JsonConversions.h:6:9: fatal error: 'GoogleMaps/GoogleMaps.h' file not found\n    #import <GoogleMaps/GoogleMaps.h>\n            ^~~~~~~~~~~~~~~~~~~~~~~~~\n    1 error generated.\n    note: Using new build system\n    note: Planning\n    note: Build preparation complete\n    note: Building targets in parallel\n    note: Removed stale file '/Users/steliospapamichail/Library/Developer/Xcode/DerivedData/Runner-czjbhkfeqllyfpfkhbtzrnpkcvgk/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/PromisesObjC.build/Script-E551D73C516C8F1E426DC570FE93233F.sh'\n    warning: Stale file '/Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/build/ios/Debug-iphonesimulator/Runner.app/Frameworks' is located outside of the allowed root paths.\n    warning: Stale file '/Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/FBLPromises.framework' is located outside of the allowed root paths.\n    warning: Stale file '/Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/FMDB.framework' is located outside of the allowed root paths.\n    warning: Stale file '/Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/FirebaseAuth.framework' is located outside of the allowed root paths.\n    warning: Stale file '/Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/FirebaseCore.framework' is located outside of the allowed root paths.\n    warning: Stale file '/Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/FirebaseCoreDiagnostics.framework' is located outside of the allowed root paths.\n    warning: Stale file '/Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/FirebaseDatabase.framework' is located outside of the allowed root paths.\n    warning: Stale file '/Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/GTMSessionFetcher.framework' is located outside of the allowed root paths.\n    warning: Stale file '/Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/GoogleDataTransport.framework' is located outside of the allowed root paths.\n    warning: Stale file '/Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/GoogleUtilities.framework' is located outside of the allowed root paths.\n    warning: Stale file '/Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/leveldb.framework' is located outside of the allowed root paths.\n    warning: Stale file '/Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/nanopb.framework' is located outside of the allowed root paths.\n    warning: Stale file '/Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/path_provider.framework' is located outside of the allowed root paths.\n    warning: Stale file '/Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/share_plus.framework' is located outside of the allowed root paths.\n    warning: Stale file '/Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/shared_preferences.framework' is located outside of the allowed root paths.\n    warning: Stale file '/Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/sqflite.framework' is located outside of the allowed root paths.\n    warning: Stale file '/Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/url_launcher.framework' is located outside of the allowed root paths.\n    warning: Stale file '/Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/build/ios/Debug-iphonesimulator/Runner.app/GoogleMaps.bundle' is located outside of the allowed root paths.\n    note: Removed stale file '/Users/steliospapamichail/Library/Developer/Xcode/DerivedData/Runner-czjbhkfeqllyfpfkhbtzrnpkcvgk/Build/Products/Debug-iphonesimulator/google_maps_flutter/google_maps_flutter.framework'\n    /Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 15.0.99. (in target 'FMDB' from project 'Pods')\n    /Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 15.0.99. (in target 'leveldb-library' from project 'Pods')\nCould not build the application for the simulator.\nError launching application on iPhone 13 Pro Max.\nExited (sigterm)\n
Run Code Online (Sandbox Code Playgroud)\n

更新 2:我意识到 VSCode 的终端没有在 Rosetta 中运行,所以当我尝试执行 pod update 或 pod install 时,我遇到了一堆错误。使用 Rosetta 打开单独的终端并运行这些命令,通过执行 pod update google_maps_flutter 修复了 google 地图错误。剩下的唯一问题是 Xcode 项目找不到 flutter.framework 目录,并且我在“框架、库和嵌入内容”下也找不到它,这导致 Xcode 的构建失败。这是堆栈:

\n
Xcode's output:\n\xe2\x86\xb3\n    /Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/ios/Runner/Runner-Bridging-Header.h:1:9:\n    note: in file included from /Users/steliospapamichail/Dropbox/Freelancing/Flutter\n    Projects/JustPlay/just_play/ios/Runner/Runner-Bridging-Header.h:1:\n    #import "GeneratedPluginRegistrant.h"\n            ^\n    /Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/ios/Runner/GeneratedPluginRegistrant.h:10:9:\n    error: 'Flutter/Flutter.h' file not found\n    #import <Flutter/Flutter.h>\n            ^\n    1 error generated.\n    <unknown>:0: error: failed to emit precompiled header\n    '/Users/steliospapamichail/Library/Developer/Xcode/DerivedData/Runner-czjbhkfeqllyfpfkhbtzrnpkcvgk/Build/Intermediates.noindex\n    /PrecompiledHeaders/Runner-Bridging-Header-swift_MU0M9NUV63KT-clang_15TXGWK3O5BI2.pch' for bridging header\n    '/Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/ios/Runner/Runner-Bridging-Header.h'\n    /Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/ios/Runner/Runner-Bridging-Header.h:1:9:\n    note: in file included from /Users/steliospapamichail/Dropbox/Freelancing/Flutter\n    Projects/JustPlay/just_play/ios/Runner/Runner-Bridging-Header.h:1:\n    #import "GeneratedPluginRegistrant.h"\n            ^\n    2 errors generated.\n    error: generate-pch command failed with exit code 1 (use -v to see invocation)\n    error: generate-pch command failed with exit code 1 (use -v to see invocation)\n    /Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/ios/Runner/Runner-Bridging-Header.h:1:9:\n    note: in file included from /Users/steliospapamichail/Dropbox/Freelancing/Flutter\n    Projects/JustPlay/just_play/ios/Runner/Runner-Bridging-Header.h:1:\n    #import "GeneratedPluginRegistrant.h"\n            ^\n    /Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/ios/Runner/GeneratedPluginRegistrant.h:10:9:\n    error: 'Flutter/Flutter.h' file not found\n    #import <Flutter/Flutter.h>\n            ^\n    1 error generated.\n    <unknown>:0: error: failed to emit precompiled header\n    '/Users/steliospapamichail/Library/Developer/Xcode/DerivedData/Runner-czjbhkfeqllyfpfkhbtzrnpkcvgk/Build/Intermediates.noindex\n    /PrecompiledHeaders/Runner-Bridging-Header-swift_20I7K2PWHDC7X-clang_2NM9DJHUIVDYE.pch' for bridging header\n    '/Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/ios/Runner/Runner-Bridging-Header.h'\n    /Users/steliospapamichail/Dropbox/Freelancing/Flutter Projects/JustPlay/just_play/ios/Runner/Runner-Bridging-Header.h:1:9:\n    note: in file included from /Users/steliospapamichail/Dropbox/Freelancing/Flutter\n    Projects/JustPlay/just_play/ios/Runner/Runner-Bridging-Header.h:1:\n    #import "GeneratedPluginRegistrant.h"\n            ^\n    2 errors generated.\n
Run Code Online (Sandbox Code Playgroud)\n

Ste*_*ail 8

在花了几天时间解决这个问题后,我“修复”了它,但不是以我引以为傲的方式,但它可能对面临同样问题的人有用。

是什么原因造成的

我最初在 Windows 计算机上开始开发,然后转移到 M1 Mac mini,以便在 iOS 模拟器上测试该应用程序。系统提示我安装可可豆荚,然后进行豆荚安装。遗憾的是,当我运行 pod install 时,遇到了有关 pod 版本不兼容的错误,我惊慌失措,导致我取消了该过程。然后我开始尝试在 StackOverflow 上找到的不同解决方案,但这只会让事情变得更糟。这些变化只是让我忘记了最初的问题是什么,因此,我无法从混乱中恢复过来。应用下面概述的步骤后,我发现最初的罪魁祸首是我在“pod install”失败并出现下面提到的错误后没有运行简单的 pod update 命令。

解决方案

以下是我纠正此问题所遵循的步骤:
  1. 创建了一个新的flutter项目
  2. 复制 android 和 lib 文件夹(因为它们没有引起任何问题)以及 pubspec.yml 和 .lock 文件。
  3. 然后,我将与 firebase 相关的文件与 SwiftDelegate 一起复制到 ios 目录中,因为我做了一些更改以支持谷歌地图。
  4. 完成后,我所要做的就是运行pod install,当不可避免地出现 pod 依赖版本问题时,我只需运行pod update即可修复 pod 遇到的任何问题。
  5. 最后一步是从Runner目标和 Pods 目标中排除该arm64架构,并将最低 ios 版本更改为 9。

就是这样,一旦这些事情完成了,一切就都正常了。

概括

总而言之,如果您像我一样在第一次使用 macOS 时遇到类似的 pod 问题,请不要惊慌,更新您的 pod 就应该没问题了。