android - 无法使 Firebase 为非 Gradle 构建工作 : Missing google_app_id. Firebase Analytics 已禁用

标签 android firebase initialization firebase-analytics

我正在开发的应用程序有一个非常定制的构建过程。无法使用 gradle 来构建我的应用程序。这并不理想,但我无法改变任何事情。 不过,我想在我的应用程序中使用 Firebase Analytics。包含模块 firebase-core、firebase-common、firebase-analytics、firebase-analytics-impl、firebase-iid、firebase-iid-interop、firebase-measurement-connector、firebase-measurement-connector-imple、play-services-测量基础和播放服务测量 API。我还将以下字符串添加到我的 strings.xml,以及我在 google-services.json 中为我的 Firebase 项目找到的值:

<string name="google_app_id" translatable="false">xxx</string>
<string name="gcm_defaultSenderId" translatable="false">xxx</string>
<string name="default_web_client_id" translatable="false">xxx</string>
<string name="firebase_database_url" translatable="false">xxx</string>
<string name="google_api_key" translatable="false">xxx</string>
<string name="google_crash_reporting_api_key" translatable="false">xxx</string>
<string name="project_id" translatable="false">xxx</string>

(如 here 所述)并从 AndroidManifest 中删除了 FirebaseInitProvider。 在我的应用程序 ApplicationonCreate() 我做的:

FirebaseOptions.Builder builder = new FirebaseOptions.Builder()
            .setApplicationId(getString(R.string.google_app_id))
            .setApiKey(getString(R.string.google_api_key));
FirebaseApp.initializeApp(this, builder.build(), "[DEFAULT]");

目前没有问题。执行上述代码时,我收到一条调试日志消息:

FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.

很好,我没有包含 auth 模块。我的应用程序不需要它。当我调用 FirebaseAnalytics.getInstance(adblockSettingsTextView.getContext()).getFirebaseInstanceId() 时,它返回一个字符串值,因此我假设初始化成功。

现在每次我想记录这样的事件

Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "Dashboard");
FirebaseAnalytics.getInstance(this).logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle);

我在日志中看到一个错误,提示 Missing google_app_id。 Firebase 分析已禁用。请参阅 https://firebase.google.com/docs/android/setup。 最重要的是,我在 Firebase Analytics 仪表板中看不到任何活跃用户。

我阅读了所有我能找到的文档,并尽我所能找出这个问题的原因。但是现在我不知道我可以检查或更改什么以使其工作。帮助将不胜感激。谢谢!

最佳答案

如果其他人遇到同样的问题,我将从 Firebase 支持那里得到的答案留在此处:

Google Analytics for Firebase (GA4F) doesn't support dynamic initialization. Our engineers are checking the possible solutions to support this. It's just that we still haven't found a definite timeline as to when (or if) this will be available.

GA4F will not work without the google-services.json file (or Gradle on your end). Even though you can initialize the FirebaseApp dynamically through code, GA4F will not recognize this and will only result in the error message you are seeing. The scenario you are getting is only specific to Google Analytics for Firebase. However, you can still use other products like Firestore, Realtime Database, Storage even if you are not using Gradle plugin.

关于android - 无法使 Firebase 为非 Gradle 构建工作 : Missing google_app_id. Firebase Analytics 已禁用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54927957/

相关文章:

java - UDACITY Sunshine Android 应用程序显示多个数据值和多个刷新选项

javascript - 如何在 Firebase 实时数据库中过滤和检索嵌套子项?

ruby-on-rails - Rails3 应用程序什么时候开始初始化?

ios - 从 Interface Builder 连接的数据源在初始化程序中返回 nil

Android:按下按钮时启动计算器

java - 我的 ListView 没有填充父项

javascript - 如何在网络中使用 Firebase 查找和删除

javascript - Firebase 中的子函数有什么作用?

c++ - 在 std::pair 支撑初始化中复制 vs move

android - Android 2.3.3 (API10) 上的下拉控件