本頁面提供使用 Firebase 時可能遇到的 Android 特定問題的提示和問題排查。
還面臨其他挑戰或沒有看到下面列出的您的問題?請務必查看主要 Firebase 常見問題解答,以了解更多泛 Firebase 或特定於產品的常見問題。
您也可以查看Firebase Android SDK GitHub 儲存庫,以取得已報告問題和故障排除的最新清單。我們鼓勵您也在那裡提交您自己的 Firebase Android SDK 相關問題!
如何解決此錯誤:「另一個專案中已存在此套件名稱和 SHA-1 的 OAuth2 用戶端」?
如果我們偵測到另一個 Firebase 或 Google Cloud 專案包含具有您指定的套件名稱和 SHA-1 的 OAuth 2.0 用戶端 ID,則會發生此錯誤。了解如何解決此錯誤。
當我將 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 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 金鑰。為了修復此錯誤,請確保所有這些條件都成立:
如何使用buildscript
語法將 Firebase 插件新增到 Android 專案?
Firebase 具有以下 Gradle 插件:
插件名稱 | Maven座標 | 最新版本 | 插件ID |
---|
Google Play 服務插件 | com.google.gms:google-services | 4.4.0 | com.google.gms.google-services |
應用程式分發插件 | com.google.firebase:firebase-appdistribution-gradle | 4.0.0 | com.google.firebase.appdistribution |
Crashlytics 插件 | com.google.firebase:firebase-crashlytics-gradle | 2.9.9 | com.google.firebase.crashlytics |
效能監控插件 | com.google.firebase:perf-plugin | 1.4.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'
...
}