React Native 0.87 กับ AGP 9: แยก Native Toolchain Migration ออกจาก Type Migration
อัป React Native แล้ว TypeScript ผ่าน ไม่ได้แปลว่า Android build พร้อมครับ รุ่น 0.87 ขยับ native toolchain หลายชั้นพร้อมกัน: Node.js ขั้นต่ำ 22.13, Kotlin 2.0 ขึ้นไป, minCompileSdk 34 และ compile SDK/build tools 37 พร้อมรองรับ Android Gradle Plugin 9
WHY: แดงเหมือนกันแต่ต้นเหตุคนละชั้น
Type error อยู่ฝั่ง JavaScript contract ส่วน Gradle sync, plugin compatibility และ manifest merge อยู่ฝั่ง native build ถ้ารวมการแก้ทั้งหมดกับ refactor หน้าจอใน PR เดียว เราจะไม่รู้ว่า failure มาจาก framework, plugin, JDK, Kotlin หรือโค้ดแอป
ประกาศ React Native 0.87 ระบุ requirement แต่ละชั้นชัด ทีมจึงควรทำ inventory ก่อนเปลี่ยน version: CI image, JDK, Gradle wrapper, AGP, Kotlin, compile SDK และ native libraries ทุกตัว
HOW: ทำ Matrix ให้เห็น Boundary
ตัวอย่างเป็นส่วนย่อของ Gradle configuration สำหรับสื่อสารค่าที่ต้องตรวจ ไม่ใช่ไฟล์ build ทั้งโปรเจกต์ และตรวจโครงสร้างเทียบกับ release notes เท่านั้น
plugins {
id("com.android.application")
kotlin("android")
}
android {
compileSdk = 37
defaultConfig {
minSdk = 24
targetSdk = 37
}
}
เริ่มด้วย branch ที่อัป template และ toolchain โดยไม่แตะ UI ให้ gradlew tasks, debug build, unit test และ instrumentation smoke test ผ่านก่อน จากนั้นจึงย้าย Strict TypeScript API เป็นอีกชุด การแยกนี้ทำให้ rollback ได้ตาม failure domain
อย่าคัดลอก minSdk จากตัวอย่างไปใช้โดยไม่ดู template ของ release และ requirement ของแอป ตัวเลขที่ release บังคับคือ minCompileSdk สำหรับ library ecosystem ขณะที่ minSdk ของแอปเป็นการตัดสินใจด้านอุปกรณ์ที่รองรับ
ตรวจ Library ก่อนโทษ Gradle
native module เก่าอาจ pin AGP API, Kotlin compiler plugin หรือ namespace behavior ที่เปลี่ยน ค้น issue/release ของ dependency ที่มีโค้ด Android และทดสอบทีละกลุ่ม ถ้าต้อง patch ชั่วคราว ให้ระบุ upstream issue และวันเอา patch ออก
บน CI ให้พิมพ์ version ของ Java, Node, Gradle, AGP และ Kotlin ใน artifact การเห็นเพียง “compile failed” โดยไม่เห็น toolchain ทำให้การเทียบเครื่อง developer กับ runner ช้าลงมาก
Recap
- ทำ inventory native toolchain และ library compatibility ก่อนอัป
- แยก PR toolchain ออกจาก Strict TypeScript API และงาน UI
- ทดสอบ Gradle sync, build, unit และ device smoke testตามลำดับ
- บันทึก version ทุกชั้นใน CI เพื่อย้อนวิเคราะห์ได้
พรุ่งนี้สร้างตาราง current/required ของ Android toolchain หนึ่งหน้า แล้วปิดช่องว่างทีละแถวครับ