xcode Firebase 配置失败 - Swift
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43412066/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Firebase configuration fails - Swift
提问by Luca Davanzo
In my application I'm successfully using Firebase and in AppDelegate I do the setup:
在我的应用程序中,我成功地使用了 Firebase,并在 AppDelegate 中进行了设置:
// ### Initialize Firebase
FIRApp.configure()
Now I do some unit testson related target and when I launch it I get errors:
现在我对相关目标进行了一些单元测试,当我启动它时出现错误:
2017-04-14 14:53:22.351 MyProject[28753] <Error> [Firebase/Core][I-COR000004] App with name __FIRAPP_DEFAULT does not exist.
2017-04-14 14:53:22.354 MyProject[28753] <Error> [Firebase/Messaging][I-IID001000] Firebase is not set up correctly. Sender ID is nil or empty.
2017-04-14 14:53:22.356 MyProject[28753] <Notice> [Firebase/Analytics][I-ACS023007] Firebase Analytics v.3800000 started
2017-04-14 14:53:22.356 MyProject[28753] <Notice> [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled
2017-04-14 14:53:22.381 MyProject[28753:712475] *** Terminating app due to uncaught exception 'com.firebase.instanceid', reason: 'Could not configure Firebase InstanceID. Google Sender ID must not be nil or empty.'
Versions:
版本:
Firebase/Core (3.16.0)
Firebase/Messagging (3.16.0)
Any advice?
有什么建议吗?
采纳答案by Michal Klein
I just noticed it's started happening to me and my travis builds are failing with Firebase 3.16. I downgraded to 3.7.1 which was the version I had previously on the project and it's working again.
我只是注意到它开始发生在我身上,我的 travis 构建在 Firebase 3.16 上失败了。我降级到 3.7.1,这是我之前在项目中使用的版本,它又可以正常工作了。
I haven't had time to look into it more but it's a quick fix. It may be a Firebase bug or they might have changed something and the setup is different now.
我没有时间仔细研究它,但这是一个快速解决方案。这可能是 Firebase 错误,或者他们可能已经更改了某些内容并且现在设置有所不同。
Edit:Apparently rolling back to 3.15 works well enough.
编辑:显然回滚到 3.15 效果很好。
回答by markshiz
Beginning in Firebase 3.16.0
, it seems Google Firebase isn't picking up the GoogleService-Info.plist
from the unit test build, even if the plist
is included in both the app and unit test targets. This doesn't seem to be resolved in 3.17.0
. As others have noted, downgrading to 3.15.0
seems to sidestep the issue.
从 Firebase 开始,3.16.0
Google Firebase 似乎没有GoogleService-Info.plist
从单元测试版本中获取,即使plist
应用程序和单元测试目标中都包含 。这似乎没有在3.17.0
. 正如其他人所指出的,降级到3.15.0
似乎回避了这个问题。
But for many, initialization of Firebase during unit tests may not be necessary, and actually unintended --for example, you probably don't want Firebase reporting on unit test crashes. In these scenarios, you can easily add a guard around FIRApp.configure()
to not initialize it while running unit tests via the following:
但是对于许多人来说,在单元测试期间初始化 Firebase 可能不是必需的,而且实际上是无意的——例如,您可能不希望 Firebase 报告单元测试崩溃。在这些场景中,您可以FIRApp.configure()
通过以下方式轻松添加一个保护,以在运行单元测试时不对其进行初始化:
import Foundation
func isUnitTesting() -> Bool {
return ProcessInfo.processInfo.environment["TEST"] != nil
}
if !isUnitTesting() {
FIRApp.configure()
}
Then be sure to define the environment variable TEST=1
onlyin your testing scheme.
然后确保TEST=1
仅在您的测试方案中定义环境变量。
回答by Rizwan Sattar
Likely Cause
可能的原因
This is likely happening due to how your Pod dependencies are being set up. Are you seeing any warnings from Xcode about multiple implementations defined in both classes, such as:
由于您的 Pod 依赖项的设置方式,这很可能会发生。您是否看到 Xcode 发出的关于在两个类中定义的多个实现的任何警告,例如:
objc[54869]: Class FIRApp is implemented in both /Users/hli/Library/Developer/CoreSimulator/Devices/7766B001-8A5F-43B6-8860-5D36E8DC452C/data/Containers/Bundle/Application/8A18B716-D1D2-4110-83E2-9AE577A034CD/FirebaseDemo.app/FirebaseDemo (0x10d306d30) and /Users/hli/Library/Developer/Xcode/DerivedData/FirebaseDemo-ddfdueufgmkxwzameiwbuhnokgax/Build/Products/Debug-iphonesimulator/FirebaseDemo.app/PlugIns/FirebaseDemoTests.xctest/FirebaseDemoTests (0x11df8cbb0). One of the two will be used. Which one is undefined.
If so, it means you probably need to tweak your pod dependencies configuration. Since a XCTest target actually also brings in the host app's target, it's possible to get multiple imports of the same object. In this case, FIRApp was initializing Instance ID, but it was causing Instance ID to check with the otherFIRApp, which was saying it wasn't configured. This explains why it's crashing saying that it can't find the app which initialized it.
如果是这样,则意味着您可能需要调整 pod 依赖项配置。由于 XCTest 目标实际上也引入了宿主应用程序的目标,因此可以获得同一对象的多个导入。在这种情况下,FIRApp 正在初始化实例 ID,但它导致实例 ID 与其他FIRApp进行检查,后者说它没有配置。这解释了为什么它会崩溃,说它找不到初始化它的应用程序。
See morganchen12@'s answer over in Github to see an example of a correct Podfile.
请参阅 Github 中的 morganchen12@'s answer 以查看正确 Podfile 的示例。
Original Answer Below:
原答案如下:
So, this is happening for possibly two reasons:
因此,发生这种情况可能有两个原因:
- Firebase can't find your
GoogleService-Info.plist
in your unit testing host app's bundle, or - The
GoogleService-Info.plist
file is either missing theGCM_SENDER_ID
key or has an empty value in it.
- Firebase
GoogleService-Info.plist
在您的单元测试主机应用程序包中找不到您,或 - 该
GoogleService-Info.plist
文件要么缺少GCM_SENDER_ID
密钥,要么其中包含空值。
We can eliminate (2) pretty easily - can you inspect your GoogleService-Info.plist
file to see if it has a valid looking GCM_SENDER_ID
(it will be a bunch of numbers, like 3252652634).
我们可以很容易地消除 (2) - 您能否检查您的GoogleService-Info.plist
文件以查看它是否具有有效外观GCM_SENDER_ID
(它将是一堆数字,例如 3252652634)。
I'll investigate why the GoogleService-Info.plist
apparently can be found with 3.15.x vs 3.16.0 and later.
我将调查为什么GoogleService-Info.plist
显然可以在 3.15.x 与 3.16.0 及更高版本中找到。
Additionally, as @markshiz said, you may not actually want Firebase to be starting up during your unit test for your app. You can put your FIRApp.configure()
call behind an if-statement, by checking if the app is running as a unit test.
此外,正如@markshiz 所说,您实际上可能不希望 Firebase 在您的应用程序的单元测试期间启动。您可以FIRApp.configure()
通过检查应用程序是否作为单元测试运行,将调用置于if 语句之后。
To also help debug this, could you run your test app with the environment variable -FIRDebugEnabled
set? The output of that would be very helpful.
为了帮助调试,您能否使用环境变量-FIRDebugEnabled
集运行您的测试应用程序?其输出将非常有帮助。
回答by Houman
It took me a while to find the correct version to install until 3.17.0 is out.
我花了一段时间才找到要安装的正确版本,直到 3.17.0 出来。
pod 'Firebase/Core', '~> 3.15.0'
pod 'Firebase/Database', '~> 3.15.0'
pod 'Firebase/Auth', '~> 3.15.0'
This works guaranteed.
这工作有保证。
If you forget the .0
and write down 3.15
instead, it would still install the faulty 3.16.0
.
如果你忘记了.0
并写下来3.15
,它仍然会安装有问题的3.16.0
.
回答by William Hu
Upgraded firebase to 4.1.0 solved my issue. Also many warnings went way. I would suggest update Firebase
将 firebase 升级到 4.1.0 解决了我的问题。许多警告也过去了。我建议更新Firebase
pod 'Firebase', '~> 4.1.0'
回答by Shikhar Singhal
Switch from a simulator to an "actual iOS device"!
从模拟器切换到“真正的 iOS 设备”!
Worked for me!
对我来说有效!
After that runs on the simulator too.
之后也在模拟器上运行。
回答by JanR
I've run into the same issue and none of the proposed fixes helped.
我遇到了同样的问题,建议的修复程序都没有帮助。
I was seeing the duplicate class implementation warnings as mentioned at the bottom of this issue: https://github.com/firebase/FirebaseUI-iOS/issues/271
我看到了这个问题底部提到的重复类实现警告:https: //github.com/firebase/FirebaseUI-iOS/issues/271
Removing all the firebase frameworks from the Test Targets as mentioned in that post has solved the issue for me.
从该帖子中提到的测试目标中删除所有 firebase 框架已经为我解决了这个问题。
回答by Quver
Have you tried this?
你试过这个吗?
let options = FIROptions(googleAppID: String!,
bundleID: String!,
gcmSenderID: String!,
apiKey: String!,
clientID: String!,
trackingID: String!,
androidClientID: String!,
databaseURL: String!,
storageBucket: String!,
deepLinkURLScheme: String!)
FIRApp.configure(with: config)
回答by Thompsonmachine
I received the same error but from the main app, and came upon this thread when searching. The following answer may not be applicable for unit tests, but I am leaving it up in case someone else lands here with the same error message but in their main app.
我收到了同样的错误,但来自主应用程序,并在搜索时遇到了这个线程。以下答案可能不适用于单元测试,但我会保留它,以防其他人在他们的主应用程序中出现相同的错误消息。
If you are receiving Google Sender ID must not be nil or empty
from your app it is probably caused by a missing entry under GCM_SENDER_ID
in the .plist
file).
如果您收到Google Sender ID must not be nil or empty
来自你的应用是在可能造成丢失的条目GCM_SENDER_ID
中.plist
的文件)。
There are 2 ways you can fix:
有两种方法可以修复:
Shotgun
霰弹枪
Just replace the entire GoogleService-Info.plist
in your project with a freshly downloaded .plist file from firebase, which should contain the proper entry for your app's GCM_SENDER_ID
.
只需使用GoogleService-Info.plist
从 firebase 新下载的 .plist 文件替换您项目中的整个文件,该文件应包含您应用的 .plist 文件的正确条目GCM_SENDER_ID
。
One-Line-of-Code
一行代码
In firebase console go to Settings (gear icon next to Overview), then Cloud Messaging. Copy the value under Sender ID
. In Xcode go to your GoogleService-Info.plist
file, create an entry for GCM_SENDER_ID
and paste in the value.
在 firebase 控制台中,转到设置(概述旁边的齿轮图标),然后转到云消息传递。复制下的值Sender ID
。在 Xcode 中,转到您的GoogleService-Info.plist
文件,创建一个条目GCM_SENDER_ID
并粘贴该值。