Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Tại Google I/O 2019, chúng tôi thông báo rằng việc phát triển Android sẽ ngày càng ưu tiên Kotlin và chúng tôi vẫn đang theo đuổi cam kết đó. Kotlin là một ngôn ngữ lập trình súc tích và rõ ràng giúp giảm các lỗi mã phổ biến và dễ dàng tích hợp vào các ứng dụng hiện có. Nếu đang muốn tạo ứng dụng Android, bạn nên bắt đầu bằng Kotlin để tận dụng các tính năng tốt nhất của Kotlin.
Trong nỗ lực hỗ trợ phát triển Android bằng Kotlin, chúng tôi là đồng sáng lập của Kotlin Foundation và liên tục đầu tư vào việc cải thiện hiệu suất của trình biên dịch cũng như tốc độ xây dựng. Để tìm hiểu thêm về cam kết của Android về việc ưu tiên Kotlin, hãy xem Cam kết của Android đối với Kotlin.
Tại sao ưu tiên Kotlin khi phát triển Android?
Chúng tôi đã xem xét ý kiến phản hồi trực tiếp của các nhà phát triển tại hội nghị, Ban tư vấn khách hàng (CAB), Google Developer Experts (GDE) và thông qua nghiên cứu của chúng tôi về nhà phát triển. Nhiều nhà phát triển ưa dùng Kotlin và thể hiện rõ mong muốn Kotlin sẽ được hỗ trợ nhiều hơn. Sau đây là những gì mà nhà phát triển đánh giá cao về việc viết bằng Kotlin:
Tính biểu đạt cao và súc tích: Bạn có thể làm được nhiều việc hơn với ít công sức hơn. Thể hiện ý tưởng và giảm số lượng mã nguyên mẫu. 67% nhà phát triển chuyên nghiệp sử dụng Kotlin cho biết Kotlin giúp tăng năng suất của họ.
Mã an toàn hơn: Kotlin có nhiều tính năng ngôn ngữ giúp bạn tránh các lỗi lập trình phổ biến, chẳng hạn như ngoại lệ đối với con trỏ rỗng.
Ứng dụng Android chứa mã Kotlin ít gặp phải sự cố hơn đến 20%.
Khả năng tương tác: Gọi mã dựa trên Java qua Kotlin, hoặc gọi Kotlin qua mã dựa trên Java. Kotlin có thể tương tác 100% với ngôn ngữ lập trình Java, vì vậy, bạn có thể sử dụng ít hoặc nhiều Kotlin trong dự án của mình tuỳ thích.
Chế độ đồng thời có cấu trúc: Các coroutine Kotlin giúp mã không đồng bộ hoạt động dễ dàng như mã chặn. Coroutine đơn giản hóa đáng kể việc quản lý tác vụ trong nền cho mọi thứ, từ lệnh gọi mạng cho đến truy cập dữ liệu cục bộ.
Ưu tiên Kotlin có nghĩa là gì?
Khi xây dựng nội dung và công cụ phát triển Android mới (chẳng hạn như Jetpack, thư viện, mẫu, tài liệu và nội dung đào tạo), chúng tôi sẽ thiết kế các công cụ và nội dung này cho người dùng Kotlin trong khi vẫn tiếp tục hỗ trợ các API bằng ngôn ngữ lập trình Java.
Ngôn ngữ Java
Kotlin
Hỗ trợ SDK nền tảng
Có
Có
Hỗ trợ Android Studio
Có
Có
Tìm lỗi mã nguồn (lint)
Có
Có
Hỗ trợ tài liệu có hướng dẫn
Có
Có
Hỗ trợ tài liệu API
Có
Có
Hỗ trợ AndroidX
Có
Có
API dành riêng cho AndroidX Kotlin (KTX, coroutine, v.v.)
Các kỹ sư của chúng tôi tận dụng những tính năng của ngôn ngữ Kotlin và hiện nay, có hơn 70 ứng dụng của Google được xây dựng bằng Kotlin. Có thể kể đến một số ứng dụng như Maps, Home, Play, Drive và Tin nhắn. Nhóm Google Home là một ví dụ thành công khi việc di chuyển hoạt động phát triển tính năng mới sang Kotlin đã giúp giảm 33% kích thước cơ sở mã (codebase) và giảm 30% số sự cố NPE.
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-07-27 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-27 UTC."],[],[],null,["# Android’s Kotlin-first approach\n\nAt Google I/O 2019, we announced that Android development will be\nincreasingly Kotlin-first, and we've stood by that commitment. Kotlin is an\nexpressive and concise programming language that reduces common code errors\nand easily integrates into existing apps. If you're looking to build an\nAndroid app, we recommend starting with Kotlin to take advantage of its\nbest-in-class features.\n\nIn an effort to support Android development using Kotlin, we co-founded the\n[Kotlin Foundation](https://kotlinlang.org/foundation/kotlin-foundation.html)\nand have ongoing investments in improving compiler performance and build\nspeed. To learn more about Android's commitment to being Kotlin-first, see\n[Android's commitment to Kotlin](https://android-developers.googleblog.com/2019/12/androids-commitment-to-kotlin.html).\n\nWhy is Android development Kotlin-first?\n----------------------------------------\n\nWe reviewed feedback that came directly from developers at conferences, our\nCustomer Advisory Board (CAB), Google Developer Experts (GDE), and through\nour developer research. Many developers already enjoy using Kotlin, and the\nrequest for more Kotlin support was clear. Here's what developers appreciate\nabout writing in Kotlin:\n\n- **Expressive and concise:** You can do more with less. Express your ideas and reduce the amount of boilerplate code. 67% of professional developers who use Kotlin say Kotlin has increased their productivity.\n- **Safer code:** Kotlin has many language features to help you avoid common programming mistakes such as null pointer exceptions. Android apps that contain Kotlin code are 20% less likely to crash.\n- **Interoperable:** Call Java-based code from Kotlin, or call Kotlin from Java-based code. Kotlin is 100% interoperable with the Java programming language, so you can have as little or as much of Kotlin in your project as you want.\n- **Structured Concurrency:** Kotlin coroutines make asynchronous code as easy to work with as blocking code. Coroutines dramatically simplify background task management for everything from network calls to accessing local data.\n\nWhat does Kotlin-first mean?\n----------------------------\n\nWhen building new Android development tools and content, such as Jetpack\nlibraries, samples, documentation, and training content, we will design\nthem with Kotlin users in mind while continuing to provide support for\nusing our APIs from the Java programming language.\n\n| | Java language | Kotlin |\n|------------------------------------------------------------|---------------|----------------------------------------------------------------------------------------------------------------------------------------|\n| Platform SDK support | Yes | Yes |\n| Android Studio support | Yes | Yes |\n| Lint | Yes | Yes |\n| Guided docs support | Yes | Yes |\n| API docs support | Yes | Yes |\n| AndroidX support | Yes | Yes |\n| AndroidX Kotlin-specific APIs (KTX, coroutines, and so on) | N/A | Yes |\n| Online training | Best effort | Yes |\n| Samples | Best effort | Yes |\n| Multi-platform projects | No | Yes |\n| Jetpack Compose | No | Yes |\n| Compiler plugin support | No | Yes - The [Kotlin Symbol Processing API](https://github.com/google/ksp) was created by Google to develop lightweight compiler plugins. |\n\nWe use Kotlin, too!\n-------------------\n\nOur engineers enjoy the language features Kotlin offers, and today over 70 of\nGoogle's apps are built using Kotlin. This includes apps like Maps, Home, Play,\nDrive, and Messages. One example of success comes from the\n[Google Home team](/stories/apps/google-home), where migrating new feature\ndevelopment to Kotlin resulted in a 33% reduction in codebase size and a 30%\nreduction in the number of NPE crashes.\n\nTo learn more about Kotlin on Android, see the\n[Kotlin on Android FAQ](/kotlin/faq)."]]