【问题标题】:Flutter ios build fails. simulator builds also failFlutter ios 构建失败。模拟器构建也失败
【发布时间】:2020-02-20 22:10:34
【问题描述】:

我几个月来一直在开发一个应用程序并使用 Flutter,但是每当我升级 Flutter 时,都会感到非常痛苦,因为我必须努力尝试让它再次构建。通常手动清理 CocoaPodspubspec.yaml 就足够了,但这次没有。

我已将我的 Flutter 版本从 1.10.7 升级到 1.14.6,对我的 pods 进行了核对和 pubspec.yaml,核对了我的 Flutter 安装、我的存储库,但没有任何效果。

关于它的另一个奇怪的事情是,我在不同机器上的同一分支上使用相同版本的颤振、飞镖、cocoapods 和 ruby​​ 构建运行良好。是否有一些东西缓存在我没有正确清理的地方?当我尝试构建时,它说它失败并出现错误,但不幸的是日志输出实际上并没有显示任何错误,而只显示警告。这是我的日志输出的一部分:

8 warnings generated.
    /Users/hallo/Documents/dev/flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in-4.1.1/ios/Classes/FLTGoogleSignInPlugin.m:138:13: warning: unused variable 'sourceApplication' [-Wunused-variable]
      NSString *sourceApplication = options[UIApplicationOpenURLOptionsSourceApplicationKey];
                ^
    /Users/hallo/Documents/dev/flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in-4.1.1/ios/Classes/FLTGoogleSignInPlugin.m:138:41: warning: 'UIApplicationOpenURLOptionsSourceApplicationKey' is only available on iOS 9.0 or newer [-Wunguarded-availability]
      NSString *sourceApplication = options[UIApplicationOpenURLOptionsSourceApplicationKey];
                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    In module 'UIKit' imported from /Users/hallo/Documents/HalloMonoRepo/hallo/ios/Pods/Target Support Files/google_sign_in/google_sign_in-prefix.pch:2:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.0.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIApplication.h:514:51: note: 'UIApplicationOpenURLOptionsSourceApplicationKey' has been marked as being introduced in iOS 9.0 here, but the deployment target is iOS 8.0.0
    UIKIT_EXTERN UIApplicationOpenURLOptionsKey const UIApplicationOpenURLOptionsSourceApplicationKey NS_SWIFT_NAME(sourceApplication) API_AVAILABLE(ios(9.0));   // value is an NSString containing the bundle ID of the originating application; non-nil if the originating application and this application share the same team identifier
                                                      ^
    /Users/hallo/Documents/dev/flutter/.pub-cache/hosted/pub.dartlang.org/google_sign_in-4.1.1/ios/Classes/FLTGoogleSignInPlugin.m:138:41: note: enclose 'UIApplicationOpenURLOptionsSourceApplicationKey' in an @available check to silence this warning
      NSString *sourceApplication = options[UIApplicationOpenURLOptionsSourceApplicationKey];
                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Could not build the application for the simulator.
Error launching application on iPhone 8.

任何帮助都将不胜感激,因为我已经用尽了关于可能导致此错误的想法。

Pluto:hallo hallo$ flutter doctor -v
[✓] Flutter (Channel beta, v1.14.6, on Mac OS X 10.14.6 18G3020, locale en-US)
• Flutter version 1.14.6 at /Users/hallo/Documents/dev/flutter
• Framework revision fabeb2a16f (3 weeks ago), 2020-01-28 07:56:51 -0800
• Engine revision c4229bfbba
• Dart version 2.8.0 (build 2.8.0-dev.5.0 fc3af737c7)


[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/hallo/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.0)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.0, Build version 11A420a
• CocoaPods version 1.8.4

[✓] Android Studio (version 3.4)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 39.0.1
• Dart plugin version 183.6270
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)

[✓] VS Code (version 1.42.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.8.1

[✓] Connected device (1 available)
• iPhone 8 • C40DD8DB-5860-4B94-8D20-372074B6E7BC • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-0 (simulator)

• No issues found!`

【问题讨论】:

  • 尝试使用-v 选项构建以获得详细日志:flutter run -v
  • ** BUILD FAILED ** The following build commands failed: PhaseScriptExecution Run\ Script /Users/hallo/Library/Developer/Xcode/DerivedData/Runner-hkmupomiwzgwwybgvjflbqilwoeu/Build/Intermediates.noindex/Runner.build/Debug-iphonesimulator/Runner.build/Script-BC68FF6F226F5DF100E3C5D3.sh (1 failure)
  • 我用 flutter run -v 得到了这个
  • 如果从 Xcode 内部运行会发生什么?

标签: flutter dart cocoapods


【解决方案1】:

您是否在 Android Studio 上运行? VS 代码?可以发一下flutter doctor -v吗?

除此之外,所有这些错误都来自google_sign_in。推荐以下:

  • 删除google_sign_in(并使用此依赖项评论任何屏幕)
  • 确保您遵循iOS Folder 中的所有正确更改
  • 使用不同的库。 google_sign_in 可能没有与所有最新的 Flutter 更改保持同步。

如果您的代码在没有该库的情况下运行,则会清楚地显示最新升级更改的错误。

【讨论】:

  • 我添加了我的颤振医生。还有 10 个其他软件包与 google_sign_in 给出的警告类似。但这很好,也许软件包已经过时并且没有新版本。不过,我确实运行了 pub upgrade 和 pod upgrade。
  • 尝试删除那些抛出错误,直到成功运行。
  • 我发现有一个 pod outdated 命令,这是它的输出,其中许多与我收到的警告非常吻合。 - abseil 0.20190808 -> (unused) (latest version 0.20190808.1) - AgoraRtcEngine_iOS 2.9.1 -> 2.9.1 (latest version 2.9.3) - BoringSSL-GRPC 0.0.3 -> 0.0.3 (latest version 0.0.5) - FBSDKCoreKit 5.15.1 -> 5.15.1 (latest version 6.0.0) - FBSDKLoginKit 5.15.1 -> 5.15.1 (latest version 6.0.0) - Flutter 1.0.0 -> 1.0.0 (latest version 1.12.1307) - gRPC-C++ 0.0.9 -> 0.0.9 (latest version 1.25.0) - gRPC-Core 1.21.0 -> 1.21.0 (latest version 1.27.0)
  • 我已经运行了 pod update,但仍然无法获取这些新版本
  • Flutter Channel Stable 也有效吗?你最近更新 XCode 了吗?
【解决方案2】:

我通过更改各种内容解决了这个问题。当我进行颤振升级时,它通过添加这一行更改了我的 project.pbxproj 文件

shellScript = "# Type a script or drag a script file from your workspace to insert its path.\n\"${PODS_ROOT}/Fabric/run\"\n"; 这导致了很多错误。我删除了这一行,将 Xcode 中的构建系统更改为默认(它是旧版),然后在 Xcode 的嵌入框架中,我删除了 Flutter.framework。

【讨论】:

    【解决方案3】:

    只需在您的项目上运行 flutter clean,它就对我有用。

    【讨论】: