Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Plugin Android Gradle 3.4.0 (April 2019)
Versi plugin Android ini perlu beberapa hal berikut:
|
Versi minimum |
Versi default |
Catatan |
Gradle |
5.1.1 |
5.1.1 |
Untuk mempelajari lebih lanjut, lihat mengupdate Gradle. Saat menggunakan Gradle 5.0 dan yang lebih baru, ukuran heap memori daemon Gradle default berkurang dari 1 GB menjadi 512 MB. Hal ini dapat menyebabkan regresi performa build. Untuk mengganti setelan default ini, tentukan ukuran heap daemon Gradle dalam file gradle.properties project Anda. |
SDK Build Tools |
28.0.3 |
28.0.3 |
Instal atau konfigurasi SDK Build Tools. |
Fitur baru
-
Konfigurasi dependensi pemeriksaan lint baru:
Perilaku lintChecks
telah berubah dan konfigurasi
dependensi baru, lintPublish
, diperkenalkan
untuk memberi Anda kontrol lebih besar atas pemeriksaan lint mana saja yang dipaketkan dalam library Android
Anda.
-
lintChecks
: Ini adalah konfigurasi aktif yang
sebaiknya Anda gunakan untuk pemeriksaan lint yang hanya ingin Anda jalankan saat membangun
project secara lokal. Jika sebelumnya
menggunakan konfigurasi dependensi lintChecks
untuk menyertakan
pemeriksaan lint dalam AAR yang dipublikasikan, Anda harus memigrasikan dependensi tersebut untuk
menggunakan konfigurasi lintPublish
baru
yang dijelaskan di bawah ini.
-
lintPublish
: Gunakan konfigurasi baru ini dalam project library untuk pemeriksaan lint
yang ingin Anda sertakan dalam AAR yang dipublikasikan,
seperti ditunjukkan di bawah ini. Artinya, project yang menggunakan library Anda
juga akan menerapkan pemeriksaan lint tersebut.
Contoh kode berikut menggunakan kedua konfigurasi dependensi pada project
library Android lokal.
dependencies {
// Executes lint checks from the ':lint' project at build time.
lintChecks project(':lint')
// Packages lint checks from the ':lintpublish' in the published AAR.
lintPublish project(':lintpublish')
}
dependencies {
// Executes lint checks from the ':lint' project at build time.
lintChecks(project(":lint"))
// Packages lint checks from the ':lintpublish' in the published AAR.
lintPublish(project(":lintpublish"))
}
Perubahan perilaku
-
Peringatan penghentian penggunaan plugin Fitur Android Instant Apps: Jika Anda masih menggunakan plugin com.android.feature
untuk membangun aplikasi instan, plugin Android Gradle 3.4.0 akan memunculkan peringatan tentang penghentian penggunaan.
Untuk memastikan Anda masih dapat membangun aplikasi instan pada versi plugin mendatang, migrasikan aplikasi instan Anda agar menggunakan plugin fitur dinamis, yang juga memungkinkan Anda memublikasikan pengalaman aplikasi terinstal dan aplikasi instan dari satu Android App Bundle.
-
R8 diaktifkan secara default: R8 mengintegrasikan desugaring, penyingkatan, obfuscation,
pengoptimalan, dan dexing ke dalam satu langkah—sehingga menghasilkan
peningkatan performa build yang nyata. R8 diperkenalkan pada plugin Android Gradle 3.3.0 dan
kini diaktifkan secara default untuk aplikasi dan project library Android yang menggunakan
plugin 3.4.0 dan yang lebih tinggi.
Gambar di bawah ini memberikan ringkasan umum tentang proses kompilasi sebelum R8 diperkenalkan.
Sekarang, dengan R8, desugaring, penyingkatan, obfuscation, pengoptimalan, dan dexing (D8) dapat diselesaikan dalam satu langkah, seperti yang diilustrasikan di bawah ini.
Perlu diperhatikan bahwa R8 dirancang agar kompatibel dengan aturan ProGuard yang telah ada, sehingga Anda mungkin tidak perlu mengambil tindakan apa pun untuk mendapatkan manfaat dari R8. Namun, karena teknologinya berbeda dengan ProGuard yang secara khusus dirancang untuk project Android, penyusutan dan pengoptimalan dapat menyebabkan penghapusan kode yang mungkin tidak dilakukan ProGuard. Jadi, dalam situasi yang jarang terjadi ini, Anda mungkin perlu
menambahkan aturan lain untuk menjaga kode tersebut pada output build Anda.
Jika mengalami masalah saat menggunakan R8, baca FAQ kompatibilitas R8 untuk memeriksa apakah ada solusi untuk masalah Anda. Jika solusi tidak terdokumentasi, silakan laporkan bug.
Anda dapat menonaktifkan R8 dengan menambahkan salah satu baris berikut ke file gradle.properties
project:
# Disables R8 for Android Library modules only.
android.enableR8.libraries = false
# Disables R8 for all modules.
android.enableR8 = false
Catatan: Untuk jenis build tertentu, jika Anda menetapkan
useProguard
ke false
dalam file
build.gradle
modul aplikasi Anda, plugin Android Gradle akan menggunakan R8 untuk menyingkat
kode aplikasi untuk jenis build tersebut, terlepas dari apakah R8 pada file gradle.properties
project Anda dinonaktifkan atau tidak.
-
ndkCompile
tidak digunakan lagi: Sekarang Anda akan melihat
error build jika mencoba menggunakan ndkBuild
untuk mengompilasi
library native. Sebagai gantinya, gunakan CMake atau ndk-build untuk
Menambahkan kode C dan C++ ke
project Anda.
Masalah umum
-
Penggunaan nama paket yang unik secara benar saat ini tidak diberlakukan, tetapi akan
diperketat pada versi plugin selanjutnya. Pada plugin Android Gradle
versi 3.4.0, Anda dapat memilih ikut serta untuk memeriksa apakah project Anda mendeklarasikan
nama paket yang dapat diterima dengan menambahkan baris di bawah ini ke file
gradle.properties
.
android.uniquePackageNames = true
Untuk mempelajari lebih lanjut cara menetapkan nama paket melalui plugin Android Gradle,
lihat Menetapkan ID aplikasi.
Konten dan contoh kode di halaman ini tunduk kepada lisensi yang dijelaskan dalam Lisensi Konten. Java dan OpenJDK adalah merek dagang atau merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2025-09-03 UTC.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-09-03 UTC."],[],[],null,["\u003cbr /\u003e\n\nAndroid Gradle Plugin 3.4.0 (April 2019)\n\nThis version of the Android plugin requires the following:\n\n| | Minimum version | Default version | Notes |\n|----------------:|:---------------:|:---------------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|\n| Gradle | 5.1.1 | 5.1.1 | To learn more, see [updating Gradle](/build/releases/gradle-plugin?buildsystem=ndk-build#updating-gradle). When using Gradle 5.0 and higher, the default Gradle daemon memory heap size decreases from 1 GB to 512 MB. This might result in a build performance regression. To override this default setting, specify the Gradle daemon heap size in your project's gradle.properties file. |\n| SDK Build Tools | 28.0.3 | 28.0.3 | [Install](/studio/intro/update#sdk-manager) or [configure](/tools/releases/build-tools) SDK Build Tools. |\n\n**3.4.3 (July 2020)**\n\n\nThis minor update supports compatibility with new default settings and\nfeatures for\n[package visibility\nin Android 11](/about/versions/11/privacy/package-visibility).\n\n\nSee the [4.0.1 release notes](#4.0.1) for details.\n\n**3.4.2 (July 2019)**\n\n\nThis minor update supports Android Studio 3.4.2 and includes various bug\nfixes and performance improvements.\nTo see a list of noteable bug fixes, read the related post on the\n[Release Updates blog](https://androidstudio.googleblog.com/2019/07/android-studio-342-available.html).\n\n**3.4.1 (May 2019)**\n\n\nThis minor update supports Android Studio 3.4.1 and includes various bug\nfixes and performance improvements.\nTo see a list of noteable bug fixes, read the related post on the\n[Release Updates blog](https://androidstudio.googleblog.com/2019/05/android-studio-341-available.html).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nNew features\n\n- **New lint check dependency configurations:** The\n behavior of `lintChecks` has changed and a new dependency\n configuration, `lintPublish`, has been introduced to give\n you more control over which lint checks are packaged in your Android\n libraries.\n\n - `lintChecks`: This is an existing configuration that you should use for lint checks you want to only run when building your project locally. If you were previously using the `lintChecks` dependency configuration to include lint checks in the published AAR, you need to migrate those dependencies to instead use the new `lintPublish` configuration described below.\n - `lintPublish`: Use this new configuration in library projects for lint checks you want to include in the published AAR, as shown below. This means that projects that consume your library also apply those lint checks.\n\n The following code sample uses both dependency configurations in a\n local Android library project. \n\n ```groovy\n dependencies {\n // Executes lint checks from the ':lint' project at build time.\n lintChecks project(':lint')\n // Packages lint checks from the ':lintpublish' in the published AAR.\n lintPublish project(':lintpublish')\n }\n \n ``` \n\n ```kotlin\n dependencies {\n // Executes lint checks from the ':lint' project at build time.\n lintChecks(project(\":lint\"))\n // Packages lint checks from the ':lintpublish' in the published AAR.\n lintPublish(project(\":lintpublish\"))\n }\n \n ```\n - In general, packaging and signing tasks should see an overall build\n speed improvement. If you notice a performance regression related to\n these tasks, please [report a bug](/studio/report-bugs).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nBehavior changes\n\n- **Android Instant Apps Feature plugin deprecation\n warning:** If you're still using the\n `com.android.feature` plugin to build your instant app,\n Android Gradle plugin 3.4.0 will give throw you a deprecation warning.\n To make sure you can still build you instant app on future versions of\n the plugin, migrate your instant app to using\n [the dynamic feature plugin](/studio/projects/dynamic-delivery),\n which also allows you to publish both your installed and instant app\n experiences from a single Android App Bundle.\n\n- **R8 enabled by default:** R8 integrates desugaring,\n shrinking, obfuscating, optimizing, and dexing all in one step---resulting\n in\n [noticeable build performance\n improvements](https://www.google.com/url?q=https://android-developers.googleblog.com/2018/11/r8-new-code-shrinker-from-google-is.html&sa=D&ust=1551922493258000&usg=AFQjCNH0N1wuMX645n7giw0wjikzjm3WCA). R8 was introduced in Android Gradle plugin 3.3.0 and\n is now enabled by default for both app and Android library projects\n using plugin 3.4.0 and higher.\n\nThe image below provides a high-level overview of the compile process\nbefore R8 was introduced.\n\nNow, with R8, desugaring, shrinking, obfuscating, optimizing, and dexing (D8)\nare all completed in one step, as illustrated below.\n\nKeep in mind, R8 is designed to work with your existing ProGuard rules, so\nyou'll likely not need to take any actions to benefit from R8. However,\nbecause it's a different technology to ProGuard that's designed specifically\nfor Android projects, shrinking and optimization may result in removing code\nthat ProGuard may have not. So, in this unlikely situation, you might need\nto add additional rules to keep that code in your build output.\n\nIf you experience issues using R8, read the\n[R8 compatibility FAQ](https://r8.googlesource.com/r8/+/refs/heads/master/compatibility-faq.md)\nto check if there's a solution to your issue. If a solution isn't documented,\nplease [report a bug](https://issuetracker.google.com/issues/new?component=326788&template=1025938).\nYou can disable R8 by adding one of the following lines to your project's\n`gradle.properties` file: \n\n # Disables R8 for Android Library modules only.\n android.enableR8.libraries = false\n # Disables R8 for all modules.\n android.enableR8 = false\n \n \n**Note:** For a given build type, if you set\n`useProguard` to `false` in your app\nmodule's `build.gradle` file, the Android Gradle plugin uses R8\nto shrink your app's code for that build type, regardless of whether you\ndisable R8 in your project's `gradle.properties` file.\n\n- **`ndkCompile` is deprecated:** You now get a build error if you try to use `ndkBuild` to compile your native libraries. You should instead use either CMake or ndk-build to [Add C and C++ code to your\n project](/studio/projects/add-native-code).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nKnown issues\n\n- The correct usage of unique package names are currently not enforced\n but will become more strict on later versions of the plugin. On Android\n Gradle plugin version 3.4.0, you can opt-in to check whether your\n project declares acceptable package names by adding the line below to\n your `gradle.properties` file.\n\n android.uniquePackageNames = true\n \n \n To learn more about setting a package name through the Android Gradle\n plugin, see\n [Set the application ID](/studio/build/configure-app-module#set_the_application_id).\n\n\u003cbr /\u003e"]]