Android Studio : Error: unmappable character for encoding UTF-8
Error: unmappable character for encoding UTF-8
error นี้สาเหตุมาจากในโค้ดโปรแกรมมีภาษาที่ไม่ใช่ภาษาอังกฤษทั่วไปปะปนเข้ามา เช่น เราใส่คอมเม็นท์เป็นภาษาไทย หรือภาษาท้องถิ่นของผู้พัฒนาเอง ทำให้ default character encoding อ่านไม่ออก วิธีแก้ไขมี 2 แบบ ดังนี้
1. Convert file to UTF-8
เราสามารถใช้โปรแกรม edit plus หรือ editor เปิดไฟล์ที่มีปัญหาแล้วทำการ Save As พร้อมกับเปลี่ยน encoding เป็น UTF-8
2. กำหนด encoding ใน Build.Gradle
เพิ่มบรรทัดที่กำหนดค่า encoding “compileOptions.encoding=” ดังรูป
android { … compileOptions.encoding = ‘UTF-8’ … } … |
จากนั้นลองคอมไพล์หรือรัน build ใหม่ครับ