使用 Firebase 进行 iOS 开发时如何修复致命错误?

Posted

技术标签:

【中文标题】使用 Firebase 进行 iOS 开发时如何修复致命错误?【英文标题】:How to fix fatal errors when working with firebase for iOS development? 【发布时间】:2020-05-06 01:55:59 【问题描述】:

首先,我在 Visual Studio 代码中工作。但这不应该是问题,因为 Flutter SDK 附带的默认代码在 ios 模拟器中运行得非常好。这是我的错误:

Launching lib/main.dart on iPhone 11 Pro Max in debug mode...
Xcode build done.                                           13.1s
Failed to build iOS app
Error output from Xcode build:
↳
    ** BUILD FAILED **
Xcode's output:
↳
    duplicate symbol '_pb_field_iter_next' in:
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_common 2.o
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_common 3.o
    duplicate symbol '_pb_field_iter_begin' in:
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_common 2.o
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_common 3.o
    duplicate symbol '_pb_field_iter_find' in:
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_common 2.o
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_common 3.o
    duplicate symbol '_pb_field_iter_next' in:
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_common 2.o
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_common.o
    duplicate symbol '_pb_field_iter_begin' in:
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_common 2.o
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_common.o
    duplicate symbol '_pb_field_iter_find' in:
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_common 2.o
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_common.o
    duplicate symbol '_pb_decode_svarint' in:
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_decode 2.o
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_decode 3.o
    duplicate symbol '_pb_decode_varint' in:
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_decode 2.o
     /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_encode.o
    duplicate symbol '_pb_write' in:
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_encode 2.o
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_encode.o
    duplicate symbol '_pb_encode_submessage' in:
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_encode 2.o
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_encode.o
    duplicate symbol '_pb_encode' in:
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_encode 2.o
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_encode.o
    duplicate symbol '_pb_encode_tag_for_field' in:
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_encode 2.o
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_encode.o
    duplicate symbol '_pb_encode_delimited' in:
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_encode 2.o
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_encode.o
    duplicate symbol '_pb_encode_nullterminated' in:
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_encode 2.o
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_encode.o
    duplicate symbol '_pb_encode_fixed64' in:
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_encode 2.o
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_encode.o
    duplicate symbol '_pb_encode_fixed32' in:
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_encode 2.o
        /Users/justindosaj/Library/Developer/Xcode/DerivedData/Runner-bchdppgbhrbnzxagnhfnozruredr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/nanopb.build/Objects-normal/x86_64/pb_encode.o
    ld: 68 duplicate symbols for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    note: Using new build system
    note: Planning build
    note: Constructing build description
Could not build the application for the simulator.
Error launching application on iPhone 11 Pro Max.
Exited (sigterm)

还需要注意的是,在此错误之前,我收到一条错误消息,提示“未找到模块 'firebase_core'”@import firebase_core

我的颤振医生:

[flutter] flutter doctor -v
Unable to find any JVMs matching version "(null)".
No Java runtime present, try --request to install.
Unable to find any JVMs matching version "(null)".
No Java runtime present, try --request to install.
[✓] Flutter (Channel stable, v1.12.13+hotfix.5, on Mac OS X 10.15.2 19C57, locale en-US)
    • Flutter version 1.12.13+hotfix.5 at /Users/justindosaj/Desktop/ApplicationSoftware/flutter
    • Framework revision 27321ebbad (6 weeks ago), 2019-12-10 18:15:01 -0800
    • Engine revision 2994f7e1e6
    • Dart version 2.7.0

[!] android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/justindosaj/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: /usr/bin/java
    ✗ Could not determine java version

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

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/setup/#android-setup for detailed instructions).

[✓] Connected device (1 available)
    • iPhone 11 Pro Max • F64065AE-360F-474C-BC50-133614E7DC6A • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-3 (simulator)

! Doctor found issues in 2 categories.
exit code 0

我的播客文件:

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'Runner' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for Runner
  pod 'Firebase/Analytics'
end

这是我的 podfile.lock

PODS:
  - Firebase/Analytics (6.15.0):
    - Firebase/Core
  - Firebase/Core (6.15.0):
    - Firebase/CoreOnly
    - FirebaseAnalytics (= 6.2.1)
  - Firebase/CoreOnly (6.15.0):
    - FirebaseCore (= 6.6.0)
  - FirebaseAnalytics (6.2.1):
    - FirebaseCore (~> 6.6)
    - FirebaseInstanceID (~> 4.3)
    - GoogleAppMeasurement (= 6.2.1)
    - GoogleUtilities/AppDelegateSwizzler (~> 6.0)
    - GoogleUtilities/MethodSwizzler (~> 6.0)
    - GoogleUtilities/Network (~> 6.0)
    - "GoogleUtilities/NSData+zlib (~> 6.0)"
    - nanopb (= 0.3.9011)
  - FirebaseCore (6.6.0):
    - FirebaseCoreDiagnostics (~> 1.2)
    - FirebaseCoreDiagnosticsInterop (~> 1.2)
    - GoogleUtilities/Environment (~> 6.5)
    - GoogleUtilities/Logger (~> 6.5)
  - FirebaseCoreDiagnostics (1.2.0):
    - FirebaseCoreDiagnosticsInterop (~> 1.2)
    - GoogleDataTransportCCTSupport (~> 1.3)
    - GoogleUtilities/Environment (~> 6.5)
    - GoogleUtilities/Logger (~> 6.5)
    - nanopb (~> 0.3.901)
  - FirebaseCoreDiagnosticsInterop (1.2.0)
  - FirebaseInstallations (1.1.0):
    - FirebaseCore (~> 6.6)
    - GoogleUtilities/UserDefaults (~> 6.5)
    - PromisesObjC (~> 1.2)
  - FirebaseInstanceID (4.3.0):
    - FirebaseCore (~> 6.6)
    - FirebaseInstallations (~> 1.0)
    - GoogleUtilities/Environment (~> 6.5)
    - GoogleUtilities/UserDefaults (~> 6.5)
  - GoogleAppMeasurement (6.2.1):
    - GoogleUtilities/AppDelegateSwizzler (~> 6.0)
    - GoogleUtilities/MethodSwizzler (~> 6.0)
    - GoogleUtilities/Network (~> 6.0)
    - "GoogleUtilities/NSData+zlib (~> 6.0)"
    - nanopb (= 0.3.9011)
  - GoogleDataTransport (3.3.0)
  - GoogleDataTransportCCTSupport (1.3.0):
    - GoogleDataTransport (~> 3.3)
    - nanopb (~> 0.3.901)
  - GoogleUtilities/AppDelegateSwizzler (6.5.0):
    - GoogleUtilities/Environment
    - GoogleUtilities/Logger
    - GoogleUtilities/Network
  - GoogleUtilities/Environment (6.5.0)
  - GoogleUtilities/Logger (6.5.0):
    - GoogleUtilities/Environment
  - GoogleUtilities/MethodSwizzler (6.5.0):
    - GoogleUtilities/Logger
  - GoogleUtilities/Network (6.5.0):
    - GoogleUtilities/Logger
    - "GoogleUtilities/NSData+zlib"
    - GoogleUtilities/Reachability
  - "GoogleUtilities/NSData+zlib (6.5.0)"
  - GoogleUtilities/Reachability (6.5.0):
    - GoogleUtilities/Logger
  - GoogleUtilities/UserDefaults (6.5.0):
    - GoogleUtilities/Logger
  - nanopb (0.3.9011):
    - nanopb/decode (= 0.3.9011)
    - nanopb/encode (= 0.3.9011)
  - nanopb/decode (0.3.9011)
  - nanopb/encode (0.3.9011)
  - PromisesObjC (1.2.8)

DEPENDENCIES:
  - Firebase/Analytics

SPEC REPOS:
  trunk:
    - Firebase
    - FirebaseAnalytics
    - FirebaseCore
    - FirebaseCoreDiagnostics
    - FirebaseCoreDiagnosticsInterop
    - FirebaseInstallations
    - FirebaseInstanceID
    - GoogleAppMeasurement
    - GoogleDataTransport
    - GoogleDataTransportCCTSupport
    - GoogleUtilities
    - nanopb
    - PromisesObjC

SPEC CHECKSUMS:
  Firebase: 5d77105d9740a07ca6b16927ca971db7e860faaf
  FirebaseAnalytics: e83e64b1231dedcd9ddd4bdecd9bcfd6ba341679
  FirebaseCore: 4aeb81ff53dcd9a3634ca725dc1fb8c2a4622046
  FirebaseCoreDiagnostics: 5e78803ab276bc5b50340e3c539c06c3de35c649
  FirebaseCoreDiagnosticsInterop: 296e2c5f5314500a850ad0b83e9e7c10b011a850
  FirebaseInstallations: 575cd32f2aec0feeb0e44f5d0110a09e5e60b47b
  FirebaseInstanceID: 6668efc1655a4052c083f287a7141f1ead12f9c2
  GoogleAppMeasurement: a08a43b8677b95ed51fcef880e36737334d804fd
  GoogleDataTransport: 574a983e829327d7c18f2627f65d9e80164ea8a4
  GoogleDataTransportCCTSupport: cad3cd6cdbdbad6b5c2c9206ec413402755faaaa
  GoogleUtilities: f8de7ddf8c706f58e9b405d53e38bbdaa2731e5a
  nanopb: 18003b5e52dab79db540fe93fe9579f399bd1ccd
  PromisesObjC: c119f3cd559f50b7ae681fa59dc1acd19173b7e6

PODFILE CHECKSUM: c6bfafa3bd987a1301ca2facd9381380dccab887

COCOAPODS: 1.8.4

我的 GoogleService-Info.plist 存储在我的运行程序文件中,我通过 Xcode 将其放入其中,因此目标应该是正确的。

发布 spec.yaml 文件:

name: testapp
description: A new Flutter project.

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
  firebase_core: ^0.4.3+2
  firebase_admob: ^0.9.0+10

dev_dependencies:
  flutter_test:
    sdk: flutter


# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  # assets:
  #  - images/a_dot_burr.jpeg
  #  - images/a_dot_ham.jpeg

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware.

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages

在我开始将 firebase 依赖项添加到我的 pubspec.yaml 文件之前,我的代码运行良好。

【问题讨论】:

你是在模拟器还是物理设备上运行? 【参考方案1】:

试试这些步骤:

    从您的ios 目录中删除.symlinkPods 文件夹。 在终端中运行flutter clean。 运行应用程序。

如果有帮助,请告诉我。

【讨论】:

以上是关于使用 Firebase 进行 iOS 开发时如何修复致命错误?的主要内容,如果未能解决你的问题,请参考以下文章

在运行时切换 Firebase 配置文件

Firebase 通知 Flutter iOS

如何在 iOS 上禁用 reCAPTCHA 验证以进行 Firebase 身份验证?

如何使用 Firebase 分发 iOS 应用程序?

如何在 UILabel 中显示名字?我正在使用 Firebase 和 Swift 开发 IOS 应用程序

swift Zero to App:使用Firebase进行开发(适用于iOS - Google I / O 2016)