本頁提供 Android 相關問題的提示和疑難排解 可協助您瞭解使用 Firebase 時可能遇到的情況
是否遇到其他挑戰,或是您的問題與下方無關?請務必勾選 請參閱 Firebase 主要常見問題 產品相關常見問題
你也可以查看 Firebase Android SDK GitHub 存放區 查看已回報的問題與疑難排解的最新清單。我們建議您 回報自己的 Firebase Android SDK 相關問題!
將 Android 應用程式新增至 Firebase 時,我需要提供 SHA-1 嗎? 專案?
SHA-1 資訊 需要 Firebase 驗證 (當使用 Google 登入或 電話號碼登入) 和 Firebase Dynamic Links。如果不使用 您不必提供 SHA-1。
如何解決這個錯誤:「已有 OAuth2 用戶端解決這個問題。 「套件名稱和 SHA-1」?
如果我們偵測到其他 Firebase 或 Google Cloud,就會發生這個錯誤 專案包含具有套件名稱的 OAuth 2.0 用戶端 ID 和 SHA-1 格式瞭解詳情 解決這個錯誤。
將 Firebase 加入 Android 專案後,我收到「找不到」錯誤。
這個錯誤通常代表應用程式缺少一或多個參考資料
Google 的 Maven 存放區請務必納入 Google 的 Maven 存放區
(google()
)。
- 如果您的專案使用
plugins
語法,請加入 的plugins
部分 (位於settings.gradle.kts
或settings.gradle
檔案。 - 如果您的專案使用
buildscript
語法,請加入 同時位於buildscript
和allprojects
專案層級build.gradle.kts
或build.gradle
檔案。
在 Android 專案中新增 Firebase SDK 後,我收到以下錯誤訊息: 叫用自訂支援並啟用脫糖功能。
2021 年 5 月 (Firebase BoM v28.0.0),Firebase 全面停用了脫糖程序 Android 程式庫 (請參閱版本資訊)。
這項變更表示使用 Android Gradle 外掛程式 (AGP) v4.2 的 Gradle 建構作業 或更早之前的版本,需要啟用 Java 8 支援功能。否則新增 Firebase SDK 時 這些 Android 專案會在建構失敗時收到以下錯誤:
D8: Invoke-customs are only supported starting with Android O (--min-api 26) Caused by: com.android.builder.dexing.DexArchiveBuilderException: Error while dexing. The dependency contains Java 8 bytecode. Please enable desugaring by adding the following to build.gradle android { compileOptions { sourceCompatibility 1.8 targetCompatibility 1.8 } } See https://developer.android.com/studio/write/java8-support.html for details. Alternatively, increase the minSdkVersion to 26 or above.
如要修正這項建構失敗的問題,您可以採用下列其中一種做法:
- 將錯誤訊息中列出的
compileOptions
新增至應用程式層級build.gradle.kts
或build.gradle
檔案。 - 將 Android 專案的
minSdkVersion
提高至 26 以上版本。
Google 登入顯示「12500」錯誤:沒什麼幫助做法 會加以修正嗎?
可能原因如下: 或缺少 SHA 金鑰。為修正這項錯誤,請完成 確認符合以下「所有」條件:
- 您已將支援電子郵件新增至 專案的一般設定 。
- 您已成功新增
版本/正式版 KeyStore 中的 SHA-1 憑證指紋
連結至 Firebase Android 應用程式 (請前往
專案設定 ,向下捲動至 然後選取「你的應用程式」,再選取「Android 應用程式」)。 - 您已成功新增
Google Play 管理中心的 SHA-1 憑證指紋
連結至 Firebase Android 應用程式 (請前往
專案設定 ,向下捲動至 然後選取「你的應用程式」,再選取「Android 應用程式」)。
如何使用 buildscript
在 Android 專案中新增 Firebase 外掛程式
語法?
Firebase 提供以下 Gradle 外掛程式:
外掛程式名稱 | Maven 座標 | 最新版本 | 外掛程式 ID |
---|---|---|---|
Google Play 服務外掛程式 | com.google.gms:google-services |
4.4.2 版 | com.google.gms.google-services |
應用程式發布外掛程式 | com.google.firebase:firebase-appdistribution-gradle |
5.0.0 | com.google.firebase.appdistribution |
Crashlytics 外掛程式 | com.google.firebase:firebase-crashlytics-gradle |
3.0.2 版 | com.google.firebase.crashlytics |
Performance Monitoring 外掛程式 | com.google.firebase:perf-plugin |
1.4.2 版 | com.google.firebase.firebase-perf |
以下說明如何將 Firebase 外掛程式新增至仍在使用
buildscript
語法:
在您的根層級 (專案層級) Gradle 檔案 (
<project>/build.gradle.kts
或<project>/build.gradle
),請將外掛程式新增為 使用 Maven 座標建立依附元件:buildscript {
repositories {
// Make sure that you have the following two repositories
google() // Google's Maven repository
mavenCentral() // Maven Central repository
}
dependencies {
...
// Add the Maven coordinates and latest version of the plugin
classpath ("PLUGIN_MAVEN_COORDINATES :PLUGIN_VERSION ")
}
}
allprojects {
...
repositories {
// Make sure that you have the following two repositories
google() // Google's Maven repository
mavenCentral() // Maven Central repository
}
}buildscript {
repositories {
// Make sure that you have the following two repositories
google() // Google's Maven repository
mavenCentral() // Maven Central repository
}
dependencies {
...
// Add the Maven coordinates and latest version of the plugin
classpath 'PLUGIN_MAVEN_COORDINATES :PLUGIN_VERSION '
}
}
allprojects {
...
repositories {
// Make sure that you have the following two repositories
google() // Google's Maven repository
mavenCentral() // Maven Central repository
}
}在「module (應用程式層級)」Gradle 檔案中 (通常是
<project>/<app-module>/build.gradle.kts
或<project>/<app-module>/build.gradle
) 用來新增外掛程式 外掛程式 ID:plugins {
id("com.android.application")
// Add the ID of the plugin
id("FIREBASE_PLUGIN_ID ")
...
}plugins {
id 'com.android.application'
// Add the ID of the plugin
id 'FIREBASE_PLUGIN_ID '
...
}