疑難排解(&A);Android 和 Firebase 常見問題
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本頁提供提示和疑難排解資訊,協助您解決使用 Firebase 時可能遇到的 Android 專屬問題。
遇到其他問題,或找不到下方列出的問題嗎?如要查看更多 Firebase 或產品專屬的常見問題,請務必參閱主要 Firebase 常見問題。
您也可以查看 Firebase Android SDK GitHub 存放區,取得最新的回報問題和疑難排解清單。我們也鼓勵您在該處回報 Firebase Android SDK 相關問題!
我收到錯誤訊息,指出系統無法解析或找不到 ktx
程式庫。
發生這項錯誤的原因可能是您使用 Firebase BoM,並將 KTX 模組指定為產品程式庫依附元件。
我們已於 2025 年 7 月停止發布 KTX 模組的新版本,並從 Firebase Android BoM (34.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 專案時,系統會顯示有關叫用自訂支援和啟用脫糖的錯誤訊息。
在 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 控制台的專案一般設定中新增支援電子郵件地址。
- 您已將發布/正式版金鑰儲存區的 SHA-1 憑證指紋新增至 Firebase 控制台的 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.4.3 |
com.google.gms.google-services |
App Distribution 外掛程式 |
com.google.firebase:firebase-appdistribution-gradle |
5.1.1 |
com.google.firebase.appdistribution |
Crashlytics 外掛程式 |
com.google.firebase:firebase-crashlytics-gradle |
3.0.5 |
com.google.firebase.crashlytics |
Performance Monitoring 外掛程式 |
com.google.firebase:perf-plugin |
2.0.0 |
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'
...
}