การแก้ปัญหา & คำถามที่พบบ่อยสำหรับ Android และ Firebase
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
หน้านี้มีเคล็ดลับและการแก้ปัญหาสำหรับปัญหาที่เกิดขึ้นกับ Android โดยเฉพาะ
ซึ่งคุณอาจพบเมื่อใช้ Firebase
หากพบความท้าทายอื่นๆ หรือไม่เห็นปัญหาของคุณที่ระบุไว้ด้านล่าง อย่าลืมดูคำถามที่พบบ่อยหลักของ Firebase เพื่อดูคำถามที่พบบ่อยเพิ่มเติมเกี่ยวกับ Firebase หรือผลิตภัณฑ์โดยเฉพาะ
นอกจากนี้ คุณยังดูรายการปัญหาที่รายงานและการแก้ปัญหาล่าสุดได้ใน
ที่เก็บ GitHub ของ Firebase Android SDK
เราขอแนะนำให้คุณ
รายงานปัญหาที่เกี่ยวข้องกับ Firebase Android SDK ของคุณที่นั่นด้วย
ฉันได้รับข้อผิดพลาดว่าktx
ไลบรารีแก้ไขไม่สำเร็จหรือ
ไม่พบ
ข้อผิดพลาดนี้อาจเกิดขึ้นเนื่องจากคุณใช้ Firebase BoM และ
ระบุโมดูล KTX เป็นการอ้างอิงไลบรารีผลิตภัณฑ์
ในเดือนกรกฎาคม 2025 เราได้หยุดเผยแพร่โมดูล KTX เวอร์ชันใหม่
และนำไลบรารี KTX ออกจาก Firebase Android BoM
(v34.0.0)
หากคุณใช้ KTX API จากโมดูล KTX ที่เผยแพร่ก่อนหน้านี้ เราขอแนะนำให้ย้ายข้อมูลแอปไปใช้ KTX API จากโมดูลหลักแทน ดูรายละเอียดได้ที่
คำถามที่พบบ่อยเกี่ยวกับโครงการนี้
ฉันจะแก้ไขข้อผิดพลาด "มีไคลเอ็นต์ OAuth2 สำหรับ
ชื่อแพ็กเกจนี้อยู่แล้ว และมี SHA-1 อยู่ในโปรเจ็กต์อื่น" ได้อย่างไร
ข้อผิดพลาดนี้จะเกิดขึ้นหากเราตรวจพบว่าโปรเจ็กต์ Firebase หรือ Google Cloud
อื่นมีรหัสไคลเอ็นต์ OAuth 2.0 ที่มีชื่อแพ็กเกจ
และ SHA-1 ที่คุณระบุ ดูวิธี
แก้ไขข้อผิดพลาดนี้
เมื่อเพิ่ม Firebase ลงในโปรเจ็กต์ Android ฉันได้รับข้อผิดพลาด "ไม่พบ"
ข้อผิดพลาดนี้มักจะหมายความว่าแอปของคุณไม่มีการอ้างอิงอย่างน้อย 1 รายการ
ไปยังที่เก็บ Maven ของ Google ตรวจสอบว่าได้รวมที่เก็บ Maven ของ Google
(google()
) ไว้ในไฟล์การกำหนดค่า Gradle
- หากโปรเจ็กต์ใช้ไวยากรณ์
plugins
ให้ใส่ไวยากรณ์นั้น
ในส่วน plugins
ในไฟล์
settings.gradle.kts
หรือ settings.gradle
- หากโปรเจ็กต์ใช้ไวยากรณ์
buildscript
ให้ใส่ไวยากรณ์ดังกล่าว
ทั้งในส่วน buildscript
และ allprojects
ในไฟล์ build.gradle.kts
หรือ
build.gradle
ระดับโปรเจ็กต์
เมื่อเพิ่ม Firebase SDK ลงในโปรเจ็กต์ Android ฉันได้รับข้อผิดพลาดเกี่ยวกับ
การรองรับ invoke-custom และการเปิดใช้การยกเลิกการลดขนาด
ในเดือนพฤษภาคม 2021 (Firebase BoM v28.0.0) Firebase ได้ปิดใช้การแยกส่วนสำหรับ
ไลบรารี Android
ทั้งหมด (ดูหมายเหตุประจำรุ่น)
การเปลี่ยนแปลงนี้หมายความว่าบิลด์ Gradle ที่ใช้ปลั๊กอิน Android Gradle (AGP) เวอร์ชัน 4.2
หรือก่อนหน้าจะต้องเปิดใช้การรองรับ 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
- เพิ่ม
minSdkVersion
สำหรับโปรเจ็กต์ Android เป็น 26 ขึ้นไป
การลงชื่อเข้าใช้ด้วย Google แสดงข้อผิดพลาด "12500:" หลังจากที่ฉันเผยแพร่แอปแล้ว ฉันจะแก้ไขข้อผิดพลาดนี้ได้อย่างไร
สาเหตุที่อาจทำให้เกิดปัญหานี้มี 2 ประการ ได้แก่ คุณไม่ได้ระบุ
อีเมลสนับสนุนหรือไม่มีคีย์ SHA หากต้องการแก้ไขข้อผิดพลาดนี้ ให้ตรวจสอบว่าเงื่อนไขต่อไปนี้ทั้งหมดเป็นจริง
วิธีเพิ่มปลั๊กอิน Firebase ลงในโปรเจ็กต์ Android โดยใช้ไวยากรณ์ buildscript
Firebase มีปลั๊กอิน Gradle ต่อไปนี้
ชื่อปลั๊กอิน |
พิกัด Maven |
เวอร์ชันล่าสุด |
รหัสปลั๊กอิน |
ปลั๊กอินบริการ 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 ลงในโปรเจ็กต์ Android ที่ยังใช้ไวยากรณ์
buildscript
มีดังนี้
ในไฟล์ Gradle ระดับรูท (ระดับโปรเจ็กต์)
(<project>/build.gradle.kts
หรือ <project>/build.gradle
) ให้เพิ่มปลั๊กอินเป็น
ทรัพยากร Dependency โดยใช้พิกัด 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
) ให้เพิ่มปลั๊กอินโดยใช้
รหัสปลั๊กอิน
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'
...
}
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-21 UTC
[null,null,["อัปเดตล่าสุด 2025-07-21 UTC"],[],[],null,["# Troubleshooting & FAQ for Android and Firebase\n\n\u003cbr /\u003e\n\nThis page offers tips and troubleshooting for Android-specific issues\nthat you might encounter when using Firebase.\n\nHave other challenges or don't see your issue outlined below? Make sure to check\nout the [main Firebase FAQ](/support/faq) for more pan-Firebase or\nproduct-specific FAQ.\n\nYou can also check out the\n[Firebase Android SDK GitHub repo](https://github.com/firebase/firebase-android-sdk/issues)\nfor an up-to-date list of reported issues and troubleshooting. We encourage you\nto file your own Firebase Android SDK related issues there, too! \n\n#### I'm getting an error that the `ktx` library failed to resolve or\ncould not be found.\n\nThis error is likely because you're using the Firebase BoM and\nspecifying a KTX module as your product library dependency.\n\n**In July 2025, we stopped releasing new versions of the KTX modules,\nand we removed the KTX libraries from the Firebase Android BoM\n(v34.0.0).**\n\nIf you use KTX APIs from previously released KTX modules, we recommend\nthat you ***migrate your app to use KTX APIs from the main modules\ninstead*** . For details, see the\n[FAQ about this initiative](/docs/android/kotlin-migration). \n\n#### Do I need to provide a SHA-1 when adding an Android app to a Firebase\nproject?\n\n[SHA-1 information](//developers.google.com/android/guides/client-auth)\nis required by Firebase Authentication (when using\n[Google signin](/docs/auth/android/google-signin) or\n[phone number signin](/docs/auth/android/phone-auth)) and\n[Firebase Dynamic Links](/docs/dynamic-links). If you're not using\nthese features, you don't have to provide a SHA-1. \n\n#### How do I resolve this error: \"An OAuth2 client already exists for this\npackage name and SHA-1 in another project\"?\n\nThis error occurs if we detect that another Firebase or Google Cloud\nproject contains an OAuth 2.0 client ID with the package name\nand SHA-1 that you specified. Learn how to\n[resolve this error](//support.google.com/firebase/answer/6401008). \n\n#### When I add Firebase to my Android project, I get a \"Could not find\" error.\n\nThis error usually means that your app is missing one or more references\nto Google's Maven repository. Make sure to include Google's Maven repository\n(`google()`) in your Gradle Configuration file.\n\n- If your project is using the `plugins` syntax, include it in the `plugins` section in your `settings.gradle.kts` or `settings.gradle` file.\n- If your project is using the `buildscript` syntax, include it in both the `buildscript` and `allprojects` sections in your project-level `build.gradle.kts` or `build.gradle` file.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n#### When I add a Firebase SDK to my Android project, I get an error about\ninvoke-custom support and enabling desugaring.\n\n\u003cbr /\u003e\n\nIn May 2021 (Firebase BoM v28.0.0), Firebase disabled desugaring for all its\nAndroid libraries\n(see [release note](/support/release-notes/android#2021-05-11)).\n\nThis change means that Gradle builds that use Android Gradle plugin (AGP) v4.2\nor earlier need to enable Java 8 support. Otherwise, when adding a Firebase SDK,\nthese Android projects get the following build failure: \n\n```\nD8: Invoke-customs are only supported starting with Android O (--min-api 26)\nCaused by: com.android.builder.dexing.DexArchiveBuilderException: Error while dexing.\nThe dependency contains Java 8 bytecode. Please enable desugaring by adding the following to build.gradle\nandroid {\n compileOptions {\n sourceCompatibility 1.8\n targetCompatibility 1.8\n }\n}\nSee https://developer.android.com/studio/write/java8-support.html for details.\nAlternatively, increase the minSdkVersion to 26 or above.\n```\n\nTo fix this build failure, you can follow one of two options:\n\n- Add the listed `compileOptions` from the error message to your **app-level** `build.gradle.kts` or `build.gradle` file.\n- Increase the `minSdkVersion` for your Android project to 26 or above.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n#### Google Sign-in is showing the error \"12500:\" after I released my app. How\ndo I fix it?\n\n\nThere are two possible reasons why this would happen: you haven't provided a\nsupport email or you're missing a SHA key. In order to fix this error, make\nsure **all** of these conditions are true:\n\n- You've added a support email to the [General Settings of your project](https://console.firebase.google.com/project/_/settings/general/) in the Firebase console.\n- You've added the [SHA-1 Certificate fingerprint from your release/production keystore](https://developers.google.com/android/guides/client-auth#using_keytool_on_the_certificate) to your Firebase Android App in the Firebase console (go to settings [**Project settings**](//console.firebase.google.com/project/_/settings/general/), scroll down to *Your apps*, and then select your Android App).\n- You've added the [SHA-1 Certificate fingerprint from the Google Play Console](https://developer.android.com/studio/publish/app-signing#api-providers) to your Firebase Android App in the Firebase console (go to settings [**Project settings**](//console.firebase.google.com/project/_/settings/general/), scroll down to *Your apps*, and then select your Android App).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n#### How to add Firebase plugins to an Android project using the `buildscript`\nsyntax?\n\n\u003cbr /\u003e\n\n| **Tip:** Consider [migrating from `buildscript` to `plugin` syntax](https://developer.android.com/build/migrate-to-kotlin-dsl#migrate-buildscript) as this allows Android Studio to perform code completion and provide other helpful suggestions.\n\nFirebase has the following Gradle plugins:\n\n| Plugin name | Maven coordinates | Latest version | Plugin ID |\n|-------------------------------|-------------------------------------------------------|----------------|---------------------------------------|\n| Google Play services plugin | `com.google.gms:google-services` | 4.4.3 | `com.google.gms.google-services` |\n| App Distribution plugin | `com.google.firebase:firebase-appdistribution-gradle` | 5.1.1 | `com.google.firebase.appdistribution` |\n| Crashlytics plugin | `com.google.firebase:firebase-crashlytics-gradle` | 3.0.6 | `com.google.firebase.crashlytics` |\n| Performance Monitoring plugin | `com.google.firebase:perf-plugin` | 2.0.1 | `com.google.firebase.firebase-perf` |\n\n\u003cbr /\u003e\n\nHere's how to add a Firebase plugin to an Android project that still uses the\n`buildscript` syntax:\n\n1. In your **root-level (project-level)** Gradle file\n (`\u003cproject\u003e/build.gradle.kts` or `\u003cproject\u003e/build.gradle`), add the plugin as\n a dependency using its Maven coordinates:\n\n ### Kotlin\n\n buildscript {\n\n repositories {\n // Make sure that you have the following two repositories\n google() // Google's Maven repository\n mavenCentral() // Maven Central repository\n }\n\n dependencies {\n ...\n\n // Add the Maven coordinates and latest version of the plugin\n classpath (\"\u003cvar translate=\"no\"\u003ePLUGIN_MAVEN_COORDINATES\u003c/var\u003e:\u003cvar translate=\"no\"\u003ePLUGIN_VERSION\u003c/var\u003e\")\n }\n }\n\n allprojects {\n ...\n\n repositories {\n // Make sure that you have the following two repositories\n google() // Google's Maven repository\n mavenCentral() // Maven Central repository\n }\n }\n\n ### Groovy\n\n buildscript {\n\n repositories {\n // Make sure that you have the following two repositories\n google() // Google's Maven repository\n mavenCentral() // Maven Central repository\n }\n\n dependencies {\n ...\n\n // Add the Maven coordinates and latest version of the plugin\n classpath '\u003cvar translate=\"no\"\u003ePLUGIN_MAVEN_COORDINATES\u003c/var\u003e:\u003cvar translate=\"no\"\u003ePLUGIN_VERSION\u003c/var\u003e'\n }\n }\n\n allprojects {\n ...\n\n repositories {\n // Make sure that you have the following two repositories\n google() // Google's Maven repository\n mavenCentral() // Maven Central repository\n }\n }\n\n2. In your **module (app-level)** Gradle file (usually\n `\u003cproject\u003e/\u003capp-module\u003e/build.gradle.kts` or\n `\u003cproject\u003e/\u003capp-module\u003e/build.gradle`), add the plugin using its\n plugin ID:\n\n ### Kotlin\n\n plugins {\n id(\"com.android.application\")\n\n // Add the ID of the plugin\n id(\"\u003cvar translate=\"no\"\u003eFIREBASE_PLUGIN_ID\u003c/var\u003e\")\n ...\n }\n\n ### Groovy\n\n plugins {\n id 'com.android.application'\n\n // Add the ID of the plugin\n id '\u003cvar translate=\"no\"\u003eFIREBASE_PLUGIN_ID\u003c/var\u003e'\n ...\n }\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e"]]