官方文檔:https://firebase.google.com/docs/android/setup?hl=zh-cn
項(xiàng)目創(chuàng)建
鏈接地址:https://console.firebase.google.com/?hl=zh-cn
應(yīng)用注冊(cè)
輸入包名众羡、SHA-1
SHA-1還可以通過(guò)gradle獲取
下載配置文件
json文件,文件中存在著對(duì)應(yīng)的應(yīng)用id,如果想?yún)^(qū)分debug和正式版本,可以通過(guò)配置不同目錄來(lái)實(shí)現(xiàn)
常見(jiàn)目錄:app/src/google-services.json
debug目錄:app/src/debug/google-services.json
Release目錄:app/src/release/google-services.json
gralde的配置:
通過(guò)debuggable true,就能讓其訪問(wèn)app/src/debug目錄,因此就可以通過(guò)配置不同key的SHA-1,來(lái)得到不同的json师妙,由此能實(shí)現(xiàn)其正式或非正式包的區(qū)分,這樣采集的奔潰和信息就會(huì)到不同的項(xiàng)目中去屹培。
buildTypes {
release {
debuggable false
//是否混淆
minifyEnabled true
//壓縮資源默穴,必須開(kāi)啟minifyEnabled才有用
shrinkResources true
//優(yōu)化對(duì)齊,可以減少apk內(nèi)存使用
zipAlignEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.typhur
}
debug {
debuggable true
//是否混淆
minifyEnabled false
//壓縮資源褪秀,必須開(kāi)啟minifyEnabled才有用
shrinkResources false
//優(yōu)化對(duì)齊蓄诽,可以減少apk內(nèi)存使用
zipAlignEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.typhurDebug
}
}
配置不同key
signingConfigs {
typhurDebug {
storeFile file('xxxx_debug.jks')
storePassword 'xxxx'
keyAlias 'xxxx_debug'
keyPassword 'xxxx'
}
typhur {
storeFile file('xxxx.jks')
storePassword 'xxxx'
keyAlias 'xxxx'
keyPassword 'xxxx'
}
}
集成Firebase SDK
project/gradle
// 新版gradle的寫法,與classpath相同
plugins {
id 'com.android.application' version '7.2.2' apply false
id 'com.android.library' version '7.2.2' apply false
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
//谷歌服務(wù)
id 'com.google.gms.google-services' version '4.3.14' apply false
//firebase崩潰分析
id 'com.google.firebase.crashlytics' version '2.8.1' apply false
//性能分析
id 'com.google.firebase.firebase-perf' version '1.4.1' apply false
}
默認(rèn)情況下溜歪,都需要集成服務(wù)若专、分析、性能分析這幾項(xiàng)
app/gradle目錄
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.google.gms.google-services'
id 'com.google.firebase.crashlytics'
id 'com.google.firebase.firebase-perf'
}
dependencies {
// bom庫(kù)蝴猪,可確保您的應(yīng)用使用的始終是 Firebase Android 庫(kù)的兼容版本
api platform('com.google.firebase:firebase-bom:30.5.0')
//谷歌分析
api 'com.google.firebase:firebase-analytics-ktx'
//性能分析
api 'com.google.firebase:firebase-perf-ktx'
//崩潰收集
api 'com.google.firebase:firebase-crashlytics-ktx'
}
AndroidManifest
<application>
<!--谷歌核心庫(kù)讀取版本所需配置-->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<!--性能分析日志-->
<meta-data
android:name="firebase_performance_logcat_enabled"
android:value="true" />
</application>
Application
override fun onCreate() {
super.onCreate()
//初始化firebase
FirebaseApp.initializeApp(this)
}
校驗(yàn)
Firebase使用
鏈接:https://console.firebase.google.com/project
基本數(shù)據(jù)查看
選擇對(duì)應(yīng)項(xiàng)目,就可以查看到該項(xiàng)目的日活數(shù)據(jù)等
奔潰問(wèn)題查看
可以查看到所有的崩潰問(wèn)題叹坦,主要是關(guān)閉debug包開(kāi)發(fā)中的問(wèn)題院峡,release可以通不過(guò)不同項(xiàng)目背桐,依此來(lái)區(qū)分是否來(lái)源于正式包的崩潰。
問(wèn)題頁(yè)面沛豌,如果已修復(fù)完成,則可以關(guān)閉
事件埋點(diǎn)
firebase的常用事件,使用方式為動(dòng)態(tài)代碼埋點(diǎn)方式