【问题标题】:Firebase (4.0.0): Use of unresolved identifier FirebaseApp when installing FirebaseDatabaseFirebase (4.0.0):安装 FirebaseDatabase 时使用未解析的标识符 FirebaseApp
【发布时间】:2017-05-19 19:17:06
【问题描述】:

会发生这样的事情:

  • 在 Xcode 版本 7.3.1 (7D1014) 上运行
  • pod 'Firebase/Core'
  • 在类中导入 Firebase

unresolved on Database

然后我添加了数据库框架

  • pod 'Firebase/Core'
  • pod 'Firebase/数据库'

unresolved on FirebaseApp

这两个框架似乎处于互斥模式。它们不能共存。

我已经尝试了一切:更新、安装、卸载、重新创建项目、重新创建工作区。全部。

愿你帮助我。上一个 Firebase 版本是否存在错误?

【问题讨论】:

  • 您能发布您的完整 Podfile 吗?我怀疑我有答案。

标签: firebase cocoapods


【解决方案1】:

我遇到了类似的问题。

您的导入语句将是:

import Firebase

确保重新启动 Xcode 并清理构建文件夹。

它对我有用并摆脱了“使用未解析的标识符 FirebaseApp ...”错误

更新:对于 Swift 4.2:FirebaseApp.configure() 确实有效。 [FIRApp 更名为 FirebaseApp]

【讨论】:

  • 这太棒了!为什么文档是错误的?!?!
  • 可能他们尚未更新文档。发生;)
  • @frank-van-puffelen 我们可以在 iOS 的文档和控制台启动指南中解决这个问题吗?
  • 如果您使用的是旧版本的 Firebase(这是 cocoapods 默认存储库指向的),这是正确的。该文档是为 Firebase 4.8+ 编写的。 Chris Edgington 在下面的回答将通过更新您的存储库(运行 pod repo update && pod update)来解决这个问题。
  • 谢谢!它给了手。
【解决方案2】:
import FirebaseCore

那么你可以使用FirebaseApp.configure()。我正在使用 swift 4。

【讨论】:

  • 这解决了我的问题,但也向我展示了我的情况出了什么问题。安装 Crashlytics 的说明仅告诉您将 pod 'Firebase/Crashlytics' 添加到您的 Podfile 中,但我认为可能假设您也已经在其中添加了 pod 'Firebase'。将 Firebase 添加到我的 Podfile,允许我使用 import Firebase 而不是 import FirebaseCore。
  • 很奇怪。文档只告诉import Firebase,它在AppDelegate.swift 中工作。但不在另一个 swift 文件中。我需要import FirebaseCore
  • Firebase 应该将它包含在文档中——我敢打赌,很多人都被这个绊倒了。伤心。对产品如此重要的文档。
【解决方案3】:

听起来您可能使用的是旧版本的 Firebase。试试 -

pod repo update
pod update

仔细检查 Firebase 4.0 是否正在安装。

还可以尝试导入特定模块。所以而不是 import Firebase 使用import FirebaseDatabase或import FirebaseAuth。

【讨论】:

  • Firebase 人员告诉我这是一个错误,他们正在提供解决方案。 Xcode 8 不会出现此问题。
  • @GiancarloMarasso 是您使用 Swift 2 还是 Swift 3 的项目?
  • 我的项目是用 Swift 2 编写的
  • 我在 Xcode 8.3.2 中遇到了同样的问题。我做了“pod repo update”和“pod update”,我的 Firebase 版本仍然显示为 3.17.0。我需要做些什么来强制它到 4.0 吗?
  • @RyanTensmeyer 在您的 Podfile 中,您是否使用任何东西来限制 Firebase pod 的版本?如果你有类似 '~> 3' 的东西,你不会得到第 4 版。
【解决方案4】:

使用 FIRApp.configure() 而不是 Firebase.configure()

【讨论】:

  • 还要确保导入 Firebase。
【解决方案5】:
sudo gem install cocoapods
pod update

【讨论】:

  • cocoapos gem 不是最新的,它在 v3.x 中安装了 firebase pod,这是正确的解决方案
  • 这应该被标记为答案。将其更改为 FIRApp 是一个过时的解决方案
  • 我同意,这应该被标记为正确答案。
  • @nzackoya ,我应该在哪个目录中更新 cocoapods??
  • @ArgaPK 您的项目目录。
【解决方案6】:

将pod 'Firebase/Core' 替换为pod 'Firebase'。 然后运行pod repo update。

【讨论】:

    【解决方案7】:

    今天对我有用:

    1.在 Xcode 9.1 中

    import UIKit
    import Firebase
    import UserNotifications
    import FirebaseInstanceID
    import FirebaseMessaging
    import FirebaseCrash
    import FirebaseAnalytics
    
    
    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate {
    
        var window: UIWindow?
    
    
        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    
            FirebaseApp.configure()
    
            return true
        }
    

    2。我的 Pod 文件

    pod 'Firebase'
      pod 'Firebase/Core'
      pod 'Firebase/Database'
      pod 'Firebase/Crash'
      pod 'Firebase/RemoteConfig'
      pod 'Firebase/Storage'
      pod 'FirebaseUI', '~> 4.0'
      pod 'Firebase/Auth'
      pod 'Firebase/Messaging'
    

    3.结局:

    pod repo update
    pod update
    

    4.重启xcode:

    5.按:shift-alt-command-k(在 xcode 中)

    这将删除构建文件夹中的所有产品和中间文件。这与删除派生数据不同。

    6.干净的

    完成

    【讨论】:

      【解决方案8】:

      就我而言,我需要import FirebaseCore 而不是import Firebase 或import FirebaseRemoteConfig。

      【讨论】:

        【解决方案9】:

        我在 podfile 中将“Firebase”和“Firebase/Core”一起放入,它对我有用

        【讨论】:

          【解决方案10】:

          它对我有用

          pod repo update
          pod update
          

          然后在 pod 文件的位置运行:

          pod install
          

          重建我的应用程序后,错误应该消失了。

          【讨论】:

            【解决方案11】:

            使用 FIRApp.configure() 代替 FirebaseApp。

            【讨论】:

            • 为我工作。这是为什么呢?
            【解决方案12】:

            对于那些面临 RemoteConfig 配置问题的人,添加一个额外的导入:

            import FirebaseRemoteConfig
            

            对我有帮助

            【讨论】:

            • 在我的情况下,需要导入的是 FirebaseCore
            【解决方案13】:

            import FirebaseCore

            将此添加到班级顶部解决了我的问题。

            FirebaseCore 版本:6.29.0

            【讨论】:

              【解决方案14】:

              这可能为时已晚,但如果您确定您的 podfile 是正确的并且您的应用程序之前已经构建过。 当这个错误突然出现时,请记住,另一个可能出错的是您的 Xcode 的增量构建文件夹。

              试试这个:

              1. 相当 Xcode
              2. 在 finder 中找到您的 Build 文件夹和 DerivedData 文件夹
              3. 删除 Build 文件夹和 DerivedData 文件夹
              4. 通过 Xcode 重建

              希望你会没事的。

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 2020-01-23
                • 1970-01-01
                • 2017-06-29
                • 2016-10-03
                • 2018-09-21
                • 1970-01-01
                • 1970-01-01
                • 2016-06-09
                相关资源
                最近更新 更多