查看 https://firebase.google.com/docs/analytics/get-started?platform=android 我们可以设置 Firebase Analytics。
dependencies {
// Import the BoM for the Firebase platform
implementation(platform("com.google.firebase:firebase-bom:33.2.0"))
// Add the dependency for the Analytics library
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation("com.google.firebase:firebase-analytics")
}
然后在MainActivity中:
private lateinit var firebaseAnalytics: FirebaseAnalytics
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Obtain the FirebaseAnalytics instance.
firebaseAnalytics = Firebase.analytics
}
但是
Firebase.analytics
还没有解决。
代替
implementation("com.google.firebase:firebase-analytics")
使用 implementation("com.google.firebase:firebase-analytics-ktx")
或者,也许设置
firebaseAnalytics = FirebaseAnalytics.getInstance(this)
。