本頁提供提示和疑難排解方法,協助您解決使用 Firebase 時可能遇到的 Android 專屬問題。
如果遇到其他問題,或下方未列出您的問題,請務必查看主要的 Firebase 常見問題,瞭解更多 Firebase 相關或特定產品的常見問題。
您也可以查看 Firebase Android SDK GitHub 存放區,取得最新回報問題和疑難排解清單。也歡迎您在該處回報 Firebase Android SDK 相關問題!
我收到錯誤訊息,指出 ktx 程式庫無法解析或找不到。
這個錯誤可能是因為您使用 Firebase BoM,並指定 KTX 模組做為產品程式庫依附元件。
2025 年 7 月,我們停止發布新版 KTX 模組,並從 Firebase Android BoM (v34.0.0) 移除 KTX 程式庫。
如果您使用先前發布的 KTX 模組中的 KTX API,建議您將應用程式遷移至使用主要模組中的 KTX API。詳情請參閱這項計畫的常見問題。
如何解決「另一個專案中已有使用這個套件名稱和 SHA-1 的 OAuth2 用戶端」錯誤?
如果系統偵測到另一個 Firebase 或 Google Cloud 專案包含 OAuth 2.0 用戶端 ID,且該 ID 具有您指定的套件名稱和 SHA-1,就會發生這項錯誤。瞭解如何解決這項錯誤。
將 Firebase 新增至 Android 專案時,系統顯示「找不到」錯誤。
這則錯誤訊息通常表示應用程式缺少一或多個 Google Maven 存放區的參照。請務必在 Gradle 設定檔中加入 Google 的 Maven 存放區 (google())。
- 如果專案使用
plugins 語法,請將其加入 settings.gradle.kts 或 settings.gradle 檔案的 plugins 區段。
- 如果專案使用
buildscript 語法,請在專案層級 build.gradle.kts 或 build.gradle 檔案的 buildscript 和 allprojects 區段中加入該語法。
將 Firebase SDK 新增至 Android 專案時,系統顯示與 invoke-custom 支援和啟用脫糖功能相關的錯誤。
2021 年 5 月 (Firebase BoM 28.0.0 版),Firebase 停用了所有 Android 程式庫的脫糖功能 (請參閱版本資訊)。
這項異動代表使用 Android Gradle 外掛程式 (AGP) 4.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) 金鑰。如要修正這項錯誤,請確認所有條件皆符合:
- 您已在 Firebase 控制台的專案一般設定中新增支援電子郵件地址。
- 您已在 Firebase 控制台中,將發布/正式版 KeyStore 的 SHA-1 憑證指紋新增至 Firebase Android 應用程式 (前往 settings專案設定,向下捲動至「您的應用程式」,然後選取 Android 應用程式)。
- 您已將 Google Play 控制台中的 SHA-1 憑證指紋新增至 Firebase 控制台中的 Firebase Android 應用程式 (前往 settings專案設定,向下捲動至「您的應用程式」,然後選取 Android 應用程式)。
如何使用 buildscript 語法將 Firebase 外掛程式新增至 Android 專案?
Firebase 包含下列 Gradle 外掛程式:
| 外掛程式名稱 |
Maven 座標 |
最新版本 |
外掛程式 ID |
| Google Play 服務外掛程式 |
com.google.gms:google-services |
4.5.0 |
com.google.gms.google-services |
| App Distribution 外掛程式 |
com.google.firebase:firebase-appdistribution-gradle |
5.3.1 |
com.google.firebase.appdistribution |
| Crashlytics 外掛程式 |
com.google.firebase:firebase-crashlytics-gradle |
3.0.8 |
com.google.firebase.crashlytics |
| Performance Monitoring 外掛程式 |
com.google.firebase:perf-plugin |
2.0.2 |
com.google.firebase.firebase-perf |
如要將 Firebase 外掛程式新增至仍使用 buildscript 語法的 Android 專案,請按照下列步驟操作:
在根層級 (專案層級) Gradle 檔案 (<project>/build.gradle.kts 或 <project>/build.gradle) 中,使用 Maven 座標將外掛程式新增為依附元件:
Kotlin
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
}
}
Groovy
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
}
}
在模組 (應用程式層級) Gradle 檔案 (通常是 <project>/<app-module>/build.gradle.kts 或 <project>/<app-module>/build.gradle) 中,使用外掛程式 ID 新增外掛程式:
Kotlin
plugins {
id("com.android.application")
// Add the ID of the plugin
id("FIREBASE_PLUGIN_ID")
...
}
Groovy
plugins {
id 'com.android.application'
// Add the ID of the plugin
id 'FIREBASE_PLUGIN_ID'
...
}