ตั้งค่าบริการ Google Play

หากต้องการพัฒนาแอปโดยใช้ API บริการ Google Play ให้ทำตามวิธีการในหน้านี้เพื่อตั้งค่าโปรเจ็กต์ด้วย SDK ที่เกี่ยวข้อง ซึ่งมีให้ใช้งานจากที่เก็บของ Google Maven

หากต้องการทดสอบแอปเมื่อใช้บริการ Google Play คุณต้องใช้วิธีใดวิธีหนึ่งต่อไปนี้

  • อุปกรณ์ Android ที่เข้ากันได้ที่ใช้ Android 5.0 (API ระดับ 21) ขึ้นไปและติดตั้งแอป Google Play Store แล้ว
  • โปรแกรมจำลอง Android ที่มี AVD ที่เรียกใช้แพลตฟอร์ม Google APIs บน Android 5.0 (API ระดับ 21) ขึ้นไป

ประกาศทรัพยากร Dependency สำหรับบริการ Google Play

หากต้องการพัฒนาฟีเจอร์ที่ใช้ API บริการ Google Play ในแอป ให้ทำตามขั้นตอนต่อไปนี้

  1. เปิดไฟล์ build.gradle ในไดเรกทอรีโมดูลของแอป

  2. สำหรับแต่ละ SDK ที่แอปของคุณต้องใช้ ให้ระบุทรัพยากร Dependency สำหรับ SDK ดังกล่าวด้วย หน้านี้มีส่วนที่แสดงรายการทรัพยากร Dependency ของบริการ Google Play ทั่วไปสำหรับแอป Android คุณอาจต้องการเพิ่มทรัพยากร Dependency ของ Firebase ลงในโปรเจ็กต์ด้วย

  3. บันทึกการเปลี่ยนแปลงและซิงค์โปรเจ็กต์

ข้อมูลโค้ดต่อไปนี้แสดงตัวอย่างไฟล์ build.gradle ที่ใช้ไลบรารีตําแหน่ง

apply plugin: 'com.android.application'

...

dependencies {
    implementation 'com.google.android.gms:play-services-location:21.0.1'
}

SDK บริการ Google Play เวอร์ชันใหม่ที่มีการแก้ไขข้อบกพร่องและฟีเจอร์ใหม่ๆ จะเผยแพร่เป็นระยะ การปรับปรุงเหล่านี้จะประกาศในบันทึกประจำรุ่น หากแอปใช้ทรัพยากร Dependency ที่ได้รับการอัปเดตแล้ว ให้เปลี่ยนไปใช้เวอร์ชันล่าสุดในทรัพยากร Dependency ของแอปเพื่อใช้ประโยชน์จากการแก้ไขเหล่านี้

ตรวจสอบว่ามีการติดตั้งบริการ Google Play หรือไม่

ตามที่อธิบายไว้ในภาพรวมของบริการ Google Play บริการ Google Play จะได้รับการอัปเดตอัตโนมัติใน Android 5.0 (API ระดับ 21) ขึ้นไป ผ่านแอป Google Play Store อย่างไรก็ตามอุปกรณ์ Android ที่ไม่มี Google Play Store จะไม่ได้ติดตั้งบริการ Google Play หากแอปทำงานบนอุปกรณ์ ที่ไม่มีบริการ Google Play คุณอาจต้องตรวจสอบว่ามีบริการ Google Play ติดตั้งอยู่ในอุปกรณ์หรือไม่ก่อนที่จะพยายามใช้ Google APIs หรือ เปิดใช้ฟีเจอร์ในแอปที่จำเป็นต้องใช้บริการ Google Play เพื่อทำงาน

หากต้องการตรวจสอบว่ามีบริการ Google Play อยู่ในอุปกรณ์หรือไม่ ให้ใช้เมธอด isGooglePlayServicesAvailable()

หากต้องการเริ่มเชื่อมต่อกับบริการ Google Play หรือดูวิธีตรวจสอบว่าเวอร์ชันของบริการ Google Play ที่ติดตั้งไว้รองรับ API ที่เฉพาะเจาะจงหรือไม่ ให้อ่านคำแนะนำเกี่ยวกับการเข้าถึง Google API

ทรัพยากร Dependency ของบริการ Google Play

ตารางต่อไปนี้แสดงทรัพยากร Dependency สำหรับบริการ Google Play ที่คุณรวมไว้ในแอป Android ได้ คุณกรองรายการตามประเภทอุปกรณ์ได้โดยเลือกปุ่มใดปุ่มหนึ่ง และค้นหากรณีการใช้งานหรือชื่อการอ้างอิงที่เฉพาะเจาะจงได้โดยป้อนข้อความลงในช่องที่ปรากฏหลังปุ่มต่างๆ

ตารางที่ 1 ทรัพยากร Dependency ของบริการ Google Play ที่จะรวมอยู่ใน แอป Android
กรณีการใช้งานและชื่อการอ้างอิง อุปกรณ์ที่รองรับ
โฆษณาในอุปกรณ์เคลื่อนที่ของ Google
com.google.android.gms:play-services-ads:22.4.0
โทรศัพท์ แท็บเล็ต
รหัสโฆษณา Android (AAID)
com.google.android.gms:play-services-ads-identifier:18.0.1
โทรศัพท์, แท็บเล็ต, Android TV, ChromeOS
โฆษณาบนอุปกรณ์เคลื่อนที่ของ Google ขนาดกะทัดรัด
com.google.android.gms:play-services-ads-lite:22.4.0
โทรศัพท์ แท็บเล็ต
โฆษณา Custom Search ของ AdSense สำหรับ Search (AFS) (CSA)
com.google.android.gms:play-services-afs-native:19.0.3
โทรศัพท์, แท็บเล็ต, ChromeOS
SDK บริการ Google Analytics สำหรับ Android
com.google.android.gms:play-services-analytics:18.0.3
เลิกใช้งานแล้ว โปรดใช้ Google Analytics สำหรับ Firebase แทน
ดัชนีแอป
com.google.android.gms:play-services-appindex:16.1.0
โทรศัพท์, แท็บเล็ต, Android TV
รหัสชุดแอป Android
com.google.android.gms:play-services-appset:16.0.2
โทรศัพท์, แท็บเล็ต, Android TV, ChromeOS
Google Sign-In สำหรับ Android
com.google.android.gms:play-services-auth:20.7.0
โทรศัพท์, แท็บเล็ต, Android TV, Auto, Android Go, ChromeOS
SMS Retriever API
com.google.android.gms:play-services-auth-api-phone:18.0.1
โทรศัพท์, แท็บเล็ต, Android Go
Block Store API (รวมถึงพื้นที่เก็บข้อมูลเข้าสู่ระบบของผู้ใช้)
com.google.android.gms:play-services-auth-blockstore:16.2.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
API การรับรู้ของ Google
com.google.android.gms:play-services-awareness:19.0.1
โทรศัพท์, แท็บเล็ต, Auto, Android Go, ChromeOS
คลาสยูทิลิตี
com.google.android.gms:play-services-base:18.2.0
โทรศัพท์, แท็บเล็ต, Android TV, Auto, Android Go, ChromeOS, Wear OS
การทดสอบของปลอมสำหรับคลาสยูทิลิตี
com.google.android.gms:play-services-base-testing:16.0.0
โทรศัพท์, แท็บเล็ต, Android TV, Auto, Android Go, ChromeOS, Wear OS
คลาสยูทิลิตีเพิ่มเติม
com.google.android.gms:play-services-basement:18.2.0
โทรศัพท์, แท็บเล็ต, Android TV, Auto, Android Go, ChromeOS, Wear OS
Google Cast
com.google.android.gms:play-services-cast:21.3.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
เฟรมเวิร์กแอปพลิเคชัน Google Cast (CAF)
com.google.android.gms:play-services-cast-framework:21.3.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
ตัวรับสัญญาณ Android TV
com.google.android.gms:play-services-cast-tv:21.0.0
Android TV
เครื่องมือสแกนโค้ด Google
com.google.android.gms:play-services-code-scanner:16.1.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
สแต็กเครือข่าย Chromium (Cronet)
com.google.android.gms:play-services-cronet:18.0.1
โทรศัพท์, แท็บเล็ต, Android TV, Auto, Android Go, ChromeOS, Wear OS
การโต้ตอบระหว่างอุปกรณ์ (DTDI)
com.google.android.gms:play-services-dtdi:16.0.0-beta01
โทรศัพท์, แท็บเล็ต, Android Go
การตรวจสอบสิทธิ์ Fast IDentity Online (FIDO)
com.google.android.gms:play-services-fido:20.1.0
โทรศัพท์, แท็บเล็ต, Android TV, Auto, Android Go, ChromeOS, Wear OS

รองรับในอุปกรณ์ที่ใช้ Android 7.0 (API ระดับ 24) ขึ้นไป
Google Fit API สำหรับ Android
com.google.android.gms:play-services-fitness:21.1.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS, Wear OS
บริการเกมของ Google Play v2 สำหรับ Android
com.google.android.gms:play-services-games-v2:19.0.0
โทรศัพท์, แท็บเล็ต, Android TV, Android Go, ChromeOS
บริการเกมของ Google Play v2 Native C SDK สำหรับ Android
com.google.android.gms:play-services-games-v2-native-c:17.0.0-beta1
โทรศัพท์, แท็บเล็ต, Android TV, Android Go, ChromeOS
บริการเกมของ Google Play v1 สำหรับ Android
com.google.android.gms:play-services-games:23.1.0
โทรศัพท์, แท็บเล็ต, Android TV, Android Go, ChromeOS
Matter API
com.google.android.gms:play-services-home:16.0.0
โทรศัพท์ แท็บเล็ต
Google Play Instant
com.google.android.gms:play-services-instantapps:18.0.1
โทรศัพท์, แท็บเล็ต, Android TV, Android Go, ChromeOS

รองรับในอุปกรณ์ที่ใช้ Android 5.0 (API ระดับ 21) ขึ้นไป
Fused Location Provider สำหรับ Android (รวมถึงการจดจำกิจกรรมและการกำหนดเขตพื้นที่เสมือน)
com.google.android.gms:play-services-location:21.0.1
โทรศัพท์, แท็บเล็ต, Android TV, Auto, Android Go, ChromeOS, Wear OS
Google Maps SDK สำหรับ Android
com.google.android.gms:play-services-maps:18.1.0
โทรศัพท์, แท็บเล็ต, Android TV, Auto, Android Go, ChromeOS, Wear OS
การสแกนบาร์โค้ดของ ML Kit
com.google.android.gms:play-services-mlkit-barcode-scanning:18.3.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
การตรวจจับใบหน้า ML Kit
com.google.android.gms:play-services-mlkit-face-detection:17.1.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
การติดป้ายกำกับรูปภาพของ ML Kit
com.google.android.gms:play-services-mlkit-image-labeling:16.0.8
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
การติดป้ายกำกับรูปภาพของ ML Kit
com.google.android.gms:play-services-mlkit-image-labeling-custom:16.0.0-beta4
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
การระบุภาษาของ ML Kit
com.google.android.gms:play-services-mlkit-language-id:17.0.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
ฟีเจอร์ช่วยตอบของ ML Kit
com.google.android.gms:play-services-mlkit-smart-reply:16.0.0-beta1
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
การจดจำข้อความของ ML Kit
com.google.android.gms:play-services-mlkit-text-recognition:19.0.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
การจดจำข้อความ ML Kit สำหรับภาษาจีน
com.google.android.gms:play-services-mlkit-text-recognition-chinese:16.0.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
การจดจําข้อความ ML Kit สำหรับเทวนาครี
com.google.android.gms:play-services-mlkit-text-recognition-devanagari:16.0.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
การจดจําข้อความ ML Kit สำหรับภาษาญี่ปุ่น
com.google.android.gms:play-services-mlkit-text-recognition-japanese:16.0.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
การจดจําข้อความ ML Kit สำหรับภาษาเกาหลี
com.google.android.gms:play-services-mlkit-text-recognition-korean:16.0.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
การค้นพบและการเชื่อมต่ออุปกรณ์ที่อยู่ใกล้เคียง
com.google.android.gms:play-services-nearby:19.0.0
โทรศัพท์, แท็บเล็ต, Android TV, Auto, Android Go
แสดงใบอนุญาตโอเพนซอร์ส
com.google.android.gms:play-services-oss-licenses:17.0.1
โทรศัพท์, แท็บเล็ต, Android TV, Auto, Android Go, ChromeOS
รองรับในอุปกรณ์ที่ใช้ Android 5.0 (API ระดับ 21) ขึ้นไป
การตรวจสอบคุณภาพการล็อกหน้าจอ
com.google.android.gms:play-services-password-complexity:18.0.1
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS, Wear OS

รองรับในอุปกรณ์ที่ใช้ Android 4.4 (API ระดับ 19) ถึง Android 9 (API ระดับ 28)
Google Pay สำหรับบัตร
com.google.android.gms:play-services-pay:16.1.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS

รองรับในอุปกรณ์ที่ใช้ Android 5.0 (API ระดับ 20) ขึ้นไป
reCAPTCHA Enterprise สำหรับการใช้เครื่องมือแอป
com.google.android.gms:play-services-recaptcha:17.0.1
โทรศัพท์, แท็บเล็ต, Android TV, Android Go, ChromeOS
SafetyNet API (รวมถึงเอกสารรับรองอุปกรณ์, Safe Browsing, reCAPTCHA และการยืนยันแอป)
com.google.android.gms:play-services-safetynet:18.0.1
โทรศัพท์, แท็บเล็ต, Android TV, Auto, Android Go, ChromeOS
Google Tag Manager
com.google.android.gms:play-services-tagmanager:18.0.3
โทรศัพท์, แท็บเล็ต, Android TV, Android Go, ChromeOS
Tasks API ใน Android
com.google.android.gms:play-services-tasks:18.0.2
โทรศัพท์, แท็บเล็ต, Android TV, Auto, Android Go, ChromeOS, Wear OS
บริการ Acceleration สำหรับ Android
com.google.android.gms:play-services-tflite-acceleration-service:16.0.0-beta01
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
TensorFlow Lite GPU Delegate API สำหรับบริการ Google Play
com.google.android.gms:play-services-tflite-gpu:16.2.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
TensorFlow Lite Java API สำหรับบริการ Google Play
com.google.android.gms:play-services-tflite-java:16.1.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
TensorFlow Lite Support API สำหรับบริการ Google Play
com.google.android.gms:play-services-tflite-support:16.1.0
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
Thread Network API
com.google.android.gms:play-services-threadnetwork:16.0.0
โทรศัพท์ แท็บเล็ต
วิสัยทัศน์สำหรับอุปกรณ์เคลื่อนที่
com.google.android.gms:play-services-vision:20.1.3
โทรศัพท์, แท็บเล็ต, Android Go, ChromeOS
Google Pay for Payments ใน Android
com.google.android.gms:play-services-wallet:19.2.1
โทรศัพท์, แท็บเล็ต, อัตโนมัติ, Android Go, ChromeOS, Wear OS
API ชั้นข้อมูลที่สวมใส่ได้
com.google.android.gms:play-services-wearable:18.1.0
โทรศัพท์, แท็บเล็ต, Wear OS

ปลั๊กอิน Gradle

บริการ Google Play ยังมีปลั๊กอิน Gradle หลายรายการตามที่แสดงในตารางต่อไปนี้ โปรดทราบว่าปุ่มที่ปรากฏก่อนตารางก่อนหน้าจะไม่เปลี่ยนแปลงข้อมูลที่ปรากฏในตารางนี้

ตารางที่ 2 รายการปลั๊กอิน Gradle ที่รวมอยู่ในบริการ Google Play
ใช้ชื่อกรณีการใช้งานและชื่อปลั๊กอิน Gradle อุปกรณ์ที่รองรับ
แสดงใบอนุญาตโอเพนซอร์ส
com.google.android.gms:oss-licenses-plugin:0.10.6
โทรศัพท์, แท็บเล็ต, ChromeOS
การตรวจสอบเวอร์ชันเข้มงวด
com.google.android.gms:strict-version-matcher-plugin:1.2.4
โทรศัพท์, แท็บเล็ต, Android TV, Auto, Android Go, ChromeOS, Wear OS