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.
Trình bổ trợ Android cho Gradle 3.1.0 (tháng 3 năm 2018)
Phiên bản trình bổ trợ Android này yêu cầu:
|
Phiên bản tối thiểu |
Phiên bản mặc định |
Lưu ý |
Gradle |
4.4 |
4.4 |
Để tìm hiểu thêm, hãy xem phần cập nhật Gradle. |
Công cụ tạo SDK |
27.0.3 |
27.0.3 |
Cài đặt hoặc định cấu hình Công cụ tạo SDK. Xin lưu ý rằng bạn không cần chỉ định phiên bản cho công cụ xây dựng bằng thuộc tính android.buildToolsVersion vì theo mặc định, trình bổ trợ sẽ sử dụng phiên bản tối thiểu cần thiết. |
Trình biên dịch DEX mới: D8
Theo mặc định, Android Studio hiện sử dụng trình biên dịch DEX mới có tên D8. Biên dịch DEX là quá trình chuyển đổi mã byte .class
thành mã byte .dex
cho Android Runtime (hoặc Dalvik cho các phiên bản Android cũ). So với trình biên dịch trước đây có tên DX, D8 biên dịch nhanh hơn và tạo các tệp DEX nhỏ hơn, trong khi vẫn có hiệu suất thời gian chạy ứng dụng bằng hoặc cao hơn.
D8 sẽ không thay đổi quy trình phát triển ứng dụng hằng ngày của bạn. Tuy nhiên, nếu bạn gặp bất cứ vấn đề nào liên quan đến trình biên dịch mới, vui lòng báo cáo lỗi. Bạn có thể tạm thời vô hiệu hoá D8 và sử dụng DX bằng cách đưa đoạn mã sau vào tệp gradle.properties
của dự án:
android.enableD8=false
Đối với các dự án sử dụng các tính năng ngôn ngữ Java 8, quá trình đơn giản hoá gia tăng được bật theo mặc định. Bạn có thể vô hiệu hoá tính năng này bằng cách chỉ định thông tin sau trong tệp gradle.properties
của dự án:
android.enableIncrementalDesugaring=false.
Người dùng xem trước: Nếu bạn đang sử dụng phiên bản xem trước của D8, hãy lưu ý rằng phiên bản này hiện biên dịch dựa trên các thư viện được đưa vào các công cụ xây dựng SDK (không phải JDK).
Vì vậy, nếu bạn đang truy cập những API có trong JDK nhưng không có trong thư viện Công cụ tạo bản dựng của SDK, bạn sẽ gặp lỗi biên dịch.
Thay đổi về hành vi
-
Khi xây dựng nhiều APK mà mỗi APK lại nhắm mục tiêu đến một ABI khác, theo mặc định, trình bổ trợ sẽ không tạo APK cho các ABI sau đây nữa: mips
, mips64
và armeabi
.
Nếu muốn xây dựng tệp APK nhắm đến những ABI như vậy, bạn phải sử dụng NDK r16b trở xuống và chỉ định ABI trong tệp build.gradle
, như minh hoạ dưới đây:
splits {
abi {
include 'armeabi', 'mips', 'mips64'
...
}
}
splits {
abi {
include("armeabi", "mips", "mips64")
...
}
}
-
Bộ nhớ đệm bản dựng của trình bổ trợ Android nay xoá các mục cũ tồn tại hơn 30 ngày trong bộ nhớ đệm.
-
Hoạt động truyền "auto"
cho resConfig
không còn tự động chọn các tài nguyên chuỗi để đóng gói vào tệp APK.
Nếu bạn tiếp tục sử dụng "auto"
, trình bổ trợ này sẽ đóng gói tất cả tài nguyên chuỗi mà ứng dụng và các phần phụ thuộc của ứng dụng đó cung cấp. Do đó, nên chỉ định từng ngôn ngữ mà bạn muốn trình bổ trợ đóng gói cho APK.
-
Vì các mô-đun cục bộ không thể phụ thuộc vào tệp APK kiểm thử của ứng dụng, nên thao tác bổ sung các phần phụ thuộc vào kiểm thử đo lường bằng cách sử dụng cấu hình androidTestApi
(thay vì androidTestImplementation
) sẽ khiến Gradle đưa ra cảnh báo sau:
WARNING: Configuration 'androidTestApi' is obsolete
and has been replaced with 'androidTestImplementation'
WARNING: Configuration 'androidTestApi' is obsolete
and has been replaced with 'androidTestImplementation'
Sửa lỗi
- Khắc phục vấn đề Android Studio không nhận dạng chính xác các phần phụ thuộc trong bản dựng kết hợp.
- Sửa lỗi đồng bộ hoá dự án xảy ra khi tải trình bổ trợ Android nhiều lần trong một bản dựng – ví dụ: khi có nhiều dự án con và dự án con nào cũng đưa trình bổ trợ Android vào trong classpath của tập lệnh buildscript.
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-09-03 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-09-03 UTC."],[],[],null,["\u003cbr /\u003e\n\nAndroid Gradle Plugin 3.1.0 (March 2018)\n\nThis version of the Android plugin requires the following:\n\n| | Minimum version | Default version | Notes |\n|----------------:|:---------------:|:---------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|\n| Gradle | 4.4 | 4.4 | To learn more, see [updating Gradle](/build/releases/gradle-plugin?buildsystem=ndk-build#updating-gradle). |\n| SDK Build Tools | 27.0.3 | 27.0.3 | [Install](/studio/intro/update#sdk-manager) or [configure](/tools/releases/build-tools) SDK Build Tools. Keep in mind, you no longer need to specify a version for the build tools using the android.buildToolsVersion property---the plugin uses the minimum required version by default. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nNew DEX compiler, D8\n\nBy default, Android Studio now uses a new DEX compiler called D8. DEX\ncompilation is the process of transforming `.class` bytecode into\n`.dex` bytecode for the Android Runtime (or Dalvik, for older\nversions of Android). Compared to the previous compiler, called DX, D8\ncompiles faster and outputs smaller DEX files, all while having the same or\nbetter app runtime performance.\n\nD8 shouldn't change your day-to-day app development workflow. However, if\nyou experience any issues related to the new compiler, please\n[report a bug](/studio/report-bugs). You can temporarily\ndisable D8 and use DX by including the following in your project's\n`gradle.properties` file: \n\n android.enableD8=false\n \nFor projects that\n[use Java 8 language features](/studio/write/java8-support),\nincremental desugaring is enabled by default. You can disable it by\nspecifying the following in your project's `gradle.properties` file: \n\n android.enableIncrementalDesugaring=false.\n \n\n**Preview users:** If you're already using a preview version of D8, note\nthat it now compiles against libraries included in the\n[SDK build tools](/studio/releases/build-tools)---not the JDK.\nSo, if you are accessing APIs that exist in the JDK but not in the SDK build\ntools libraries, you get a compile error.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nBehavior changes\n\n- When building multiple APKs that each target a different ABI, the\n no longer generates APKs for the following ABIs by default:\n `mips`, `mips64`, and `armeabi`.\n\n If you want to build APKs that target these ABIs, you must use\n [NDK r16b or lower](/ndk/downloads/revision_history) and\n specify the ABIs in your `build.gradle` file, as shown below: \n\n ```groovy\n splits {\n abi {\n include 'armeabi', 'mips', 'mips64'\n ...\n }\n }\n \n ``` \n\n ```kotlin\n splits {\n abi {\n include(\"armeabi\", \"mips\", \"mips64\")\n ...\n }\n }\n \n ```\n- The Android plugin's [build\n cache](/studio/build/build-cache) now evicts cache entries that are older than 30 days.\n\n- Passing `\"auto\"` to\n [`resConfig`](https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.ProductFlavor.html#com.android.build.gradle.internal.dsl.ProductFlavor:resConfig(java.lang.String))\n no longer automatically picks string resources to package into your APK.\n If you continue to use `\"auto\"`, the plugin packages all string\n resources your app and its dependencies provide. So, you should instead\n specify each locale that you want the plugin to package into your APK.\n\n- Because local modules can't depend on your app's test APK, adding\n dependencies to your instrumented tests using the\n `androidTestApi` configuration, instead of\n `androidTestImplementation`, causes Gradle to issue the\n following warning:\n\n ```groovy\n WARNING: Configuration 'androidTestApi' is obsolete\n and has been replaced with 'androidTestImplementation'\n \n ``` \n\n ```kotlin\n WARNING: Configuration 'androidTestApi' is obsolete\n and has been replaced with 'androidTestImplementation'\n \n ```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nFixes\n\n- Fixes an issue where Android Studio doesn't properly recognize dependencies in composite builds.\n- Fixes an issue where you get a project sync error when loading the Android plugin multiple times in a single build--for example, when multiple subprojects each include the Android plugin in their buildscript classpath.\n\n\u003cbr /\u003e"]]