简体   繁体   English

在运行时为 Analytics logEvents 初始化 Firebase 不起作用

[英]Initializing Firebase at Runtime for Analytics logEvents not working

I have an app that needs 2 Firebase projects.我有一个需要 2 Firebase 项目的应用程序。 Depending on the login option used, i need to logEvents to a specific Firebase project.根据使用的登录选项,我需要将事件记录到特定的logEvents项目。

I cannot use multiple google-services.json in different directories based on build variant/flavor because it needs to be one app.我不能根据构建变体/风格在不同目录中使用多个google-services.json ,因为它需要是一个应用程序。 As such, i因此,我

  1. Deleted google-services.json from the project从项目中删除了google-services.json

  2. commented apply plugin: 'com.google.gms.google-services' in gradle在 gradle 中评论了apply plugin: 'com.google.gms.google-services'

  3. Initialized Firebase with below code using values from google-services.json file使用google-services.json文件中的值使用以下代码初始化 Firebase

     val firebaseOptions = Builder().setApplicationId("client.client_info.mobilesdk_app_id").setApiKey("client.client_info.current_key").setDatabaseUrl("project_info.firebase_url").setGcmSenderId("project_info.project_number").setStorageBucket("project_info.storage_bucket").setProjectId("project_info.project_id").build() FirebaseApp.initializeApp(context, firebaseOptions, "[DEFAULT]")

I'm getting below error though.不过,我遇到了错误。

E/FA: Missing google_app_id. Firebase Analytics disabled.
E/FA: Uploading is not possible. App measurement disabled

Is there a way to solve this issue?有没有办法解决这个问题? I need to initialize Firebase at runtime after a user action and logEvents to Firebase我需要在用户操作后在运行时初始化 Firebase 并将 logEvents 初始化为 Firebase

I think what you are trying to achieve is not possible, I dig around a little bit more, and the experience you are getting is the expected behavior: Analytics does not work with builder (custom) initialization .我认为您想要实现的目标是不可能的,我进行了更多挖掘,您获得的经验是预期的行为: Analytics does not work with builder (custom) initialization

You can check a statement from the firebase support team here: Unable to make Firebase work for a non Gradle build: Missing google_app_id.您可以在此处查看 firebase 支持团队的声明: 无法使 Firebase 工作于非 Gradle 版本:缺少 google_app_id。 Firebase Analytics disabled Firebase 禁用分析

Yet, I discovered this two workarounds on a thread on GitHub, but they do not apply to your use case since it's done at compilation time.然而,我在 GitHub 上的一个线程上发现了这两个解决方法,但它们不适用于您的用例,因为它是在编译时完成的。

Workaround: https://github.com/firebase/firebase-android-sdk/issues/66#issuecomment-697341745 https://github.com/firebase/firebase-android-sdk/issues/66#issuecomment-755434814解决方法: https://github.com/firebase/firebase-android-sdk/issues/66#issuecomment-697341745 https://github.com/firebase/firebase-android-sdk/issues/66#issuecomment-755434814

I suggest you to move your analytics to another provider in case this is a stopper for you, or just leave analytics on a single project and add an attribute to differentiate between user/flows.我建议您将您的分析转移到另一个供应商,以防这对您来说是一个障碍,或者只是将分析留在单个项目上并添加一个属性来区分用户/流。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM