本頁面提供有關使用 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.3.15 | 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'
...
}