คู่มือการย้ายข้อมูล Android Consumer SDK 3.0
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ย้ายข้อมูลไปยัง Kotlin 2.0
หากใช้ Consumer SDK สำหรับ Android 3.0 ขึ้นไป คุณต้องอัปเกรดเป็น Kotlin
2.0 หน้านี้ให้คำแนะนำเพื่อช่วยให้การเปลี่ยนไปใช้ Kotlin เวอร์ชันใหม่เป็นไปอย่างราบรื่น
ความเข้ากันได้ของ Gradle และ AGP
Kotlin 2.0 มีข้อกำหนดสำหรับเวอร์ชันขั้นต่ำและสูงสุด
สำหรับ Gradle และปลั๊กอิน Android Gradle (AGP) ตรวจสอบว่าโปรเจ็กต์ของคุณเป็นไปตามข้อกำหนดเหล่านี้สำหรับ Kotlin 2.0
AGP เวอร์ชันขั้นต่ำสำหรับ Consumer SDK 3.0 ขึ้นไป
Consumer SDK 3.0 ต้องใช้ AGP 7.3 ขึ้นไป
โหมด R8 เต็มรูปแบบ
SDK สำหรับผู้ใช้ทั่วไป v3 และเวอร์ชันที่ต่ำกว่าไม่รองรับโหมด R8 แบบเต็ม คุณต้องปิดใช้โหมด R8 แบบเต็มอย่างชัดแจ้ง
หากแอปพลิเคชันกำหนดเป้าหมายเป็น AGP 8.0 ขึ้นไป
# settings.gradle
android.enableR8.fullMode=false
ความเข้ากันได้ของเวอร์ชัน Kotlin
Kotlin รองรับความเข้ากันได้แบบย้อนหลังกับภาษา 3 เวอร์ชันก่อนหน้า
ซึ่งหมายความว่าหากคุณใช้ Kotlin 1.7 ขึ้นไปกับ Consumer SDK อยู่แล้ว คุณควรจะอัปเกรดเป็น Kotlin 2.0 ได้โดยไม่ต้องแก้ไขการเปลี่ยนแปลงที่ทำให้เกิดข้อขัดข้องทั้งหมด
อย่างไรก็ตาม ความเข้ากันได้ของ Kotlin มีผลกับฟีเจอร์ภาษาที่เสถียรเท่านั้น
หากคุณใช้ฟีเจอร์เวอร์ชันอัลฟ่า เบต้า หรือฟีเจอร์ทดลองในภาษา Kotlin
คุณอาจต้องทำการเปลี่ยนแปลงเพิ่มเติมเมื่ออัปเกรด
Flag ความเข้ากันได้ของ Kotlin
ดังที่ระบุไว้ในส่วนก่อนหน้า Kotlin รองรับภาษาเวอร์ชันก่อนหน้าสูงสุด 3 เวอร์ชันเมื่ออัปเกรด Kotlin มี 2 แฟล็กที่จะช่วยจำกัด�
การเปลี่ยนแปลงที่ทำให้เกิดข้อขัดข้อง ดังนี้
language-version X.Y
โดยแฟล็กนี้จะเปลี่ยนการเปลี่ยนแปลงที่ส่งผลกับส่วนอื่นในระบบกลับไปเป็นลักษณะการทำงานของ Kotlin เวอร์ชันก่อนหน้า
ตัวอย่างเช่น หากคุณใช้ Kotlin 1.7 คุณสามารถระบุ [ -
language-version 1.7]
และการเปลี่ยนแปลงที่ทำให้เกิดข้อขัดข้องใหม่จะไม่ส่งผลอีกต่อไป
android {
kotlinOptions {
languageVersion = '1.7'
}
}
api-version X.Y
โดยแฟล็กนี้จะป้องกันไม่ให้มีการใช้ API ใหม่ก่อนที่โค้ดดาวน์สตรีมที่ขึ้นอยู่กับ API นั้นๆ จะพร้อมรวม Kotlin 2.0
android {
kotlinOptions {
apiVersion = '1.7'
}
}
แนวทางที่ตรงเป้าหมายมากขึ้น
นอกเหนือจากการใช้แฟล็กความเข้ากันได้ของ Kotlin แล้ว เราขอแนะนำให้คุณอ่าน
หมายเหตุประจำรุ่นของ Kotlin และเลือกลักษณะการทำงานที่ต้องการเก็บไว้
จากเวอร์ชันที่คุณอัปเกรด Kotlin มีรายการการเปลี่ยนแปลงที่ทำให้เกิดข้อขัดข้องและค่าสถานะที่ตั้งค่าเพื่อคงลักษณะการทำงานเดิมไว้ในคู่มือความเข้ากันได้สำหรับแต่ละเวอร์ชัน
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-31 UTC
[null,null,["อัปเดตล่าสุด 2025-08-31 UTC"],[[["\u003cp\u003eUpgrading to Kotlin 2.0 is mandatory when utilizing the Consumer SDK for Android 3.0 or later.\u003c/p\u003e\n"],["\u003cp\u003eEnsure your Gradle and Android Gradle Plugin (AGP) versions meet the compatibility requirements for Kotlin 2.0, with Consumer SDK 3.0+ necessitating AGP 7.3 or higher.\u003c/p\u003e\n"],["\u003cp\u003eDisable Full R8 mode explicitly for Consumer SDK v3 and below when targeting AGP 8.0+.\u003c/p\u003e\n"],["\u003cp\u003eWhile Kotlin generally offers backward compatibility, potential breaking changes might require adjustments, especially when using alpha, beta, or experimental Kotlin features.\u003c/p\u003e\n"],["\u003cp\u003eLeverage Kotlin compatibility flags like \u003ccode\u003elanguage-version\u003c/code\u003e and \u003ccode\u003eapi-version\u003c/code\u003e or consult the Kotlin compatibility guides for managing specific breaking changes during the upgrade.\u003c/p\u003e\n"]]],["To migrate to Kotlin 2.0 with Consumer SDK 3.0+, ensure your Gradle and AGP versions meet Kotlin 2.0 requirements (AGP 7.3+). Disable Full R8 mode if using AGP 8.0+ by setting `android.enableR8.fullMode=false` in `settings.gradle`. Utilize Kotlin compatibility flags, `languageVersion` and `apiVersion`, to revert breaking changes or limit new API usage. Consult the Kotlin compatibility guides for specific version changes and behavior flags.\n"],null,["Migrate to Kotlin 2.0\n\nIf you are using the Consumer SDK for Android 3.0+ you must upgrade to Kotlin\n2.0. This page provides guidance to ease the transition to the new Kotlin\nversion.\n| **Note:** For information on upgrading to Kotlin 1.9, which was required for the Consumer SDK 5.0+ see the [Kotlin 1.9 upgrade\n| guide](/maps/documentation/transportation-logistics/on-demand-rides-deliveries-solution/trip-order-progress/migrations/android_consumer_sdk_v2.0_migration#kotlin_16_to_19_migration).\n\nGradle and AGP compatibility\n\nKotlin 2.0 has [requirements for the minimum and maximum\nversions](https://kotlinlang.org/docs/gradle-configure-project.html#apply-the-plugin)\nfor your Gradle and Android Gradle Plugin (AGP) version. Ensure that your\nproject meets these requirements for Kotlin 2.0.\n\nAGP minimum version for the Consumer SDK 3.0+\n\nConsumer SDK 3.0 requires using AGP 7.3+.\n\nFull R8 mode\n\nConsumer SDK v3 and below does not support Full R8 mode. You must explicitly\ndisable Full R8 mode if your application targets AGP 8.0+. \n\n # settings.gradle\n android.enableR8.fullMode=false\n\nKotlin version compatibility\n\nKotlin supports backwards compatibility with [three previous language\nversions](https://kotlinlang.org/docs/kotlin-evolution-principles.html#compatibility-options).\nThis means that if you are already using Kotlin 1.7+ with the Consumer SDK, you\nshould be able to upgrade to Kotlin 2.0 without having to resolve all of the\nbreaking changes. However, [Kotlin compatibility only applies to stable language\nfeatures](https://kotlinlang.org/docs/components-stability.html#stability-levels-explained).\nIf you are using alpha, beta or experimental features in the Kotlin language,\nthen you may have to make additional changes when upgrading.\n\nKotlin compatibility flags\n\nAs noted in the previous section, Kotlin supports up to 3 previous versions of\nthe language when upgrading. Kotlin [supplies two flags to help with limiting\nbreaking changes](https://kotlinlang.org/docs/compatibility-modes.html):\n\nlanguage-version X.Y\n\nThis flag reverts breaking changes to the behavior of a previous Kotlin version.\nFor example, if you are using Kotlin 1.7, you could specify `[ -\nlanguage-version 1.7]` and the new breaking changes would no longer take effect: \n\n android {\n kotlinOptions {\n languageVersion = '1.7'\n }\n }\n\napi-version X.Y\n\nThis flag prevents new APIs from being used before dependent downstream code is\nready to incorporate Kotlin 2.0. \n\n android {\n kotlinOptions {\n apiVersion = '1.7'\n }\n }\n\nA more targeted approach\n\nIn addition to using Kotlin compatibility flags, we recommend reviewing the\nKotlin release notes and choosing the behaviors that you would like to retain\nfrom the version that you are upgrading from. Kotlin provides a list of breaking\nchanges and the flags that can be set to retain the original behavior in its\ncompatibility guides for each version:\n\n- [1.8 compatibility guide](https://kotlinlang.org/docs/compatibility-guide-18.html)\n- [1.9 compatibility guide](https://kotlinlang.org/docs/compatibility-guide-19.html)\n- [2.0 compatibility guide](https://kotlinlang.org/docs/compatibility-guide-20.html)"]]