จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ปลั๊กอิน Android Gradle 3.1.0 (มีนาคม 2018)
ปลั๊กอิน Android เวอร์ชันนี้กำหนดให้ต้องมีสิ่งต่อไปนี้
|
เวอร์ชันขั้นต่ำ |
เวอร์ชันเริ่มต้น |
หมายเหตุ |
Gradle |
4.4 |
4.4 |
ดูข้อมูลเพิ่มเติมได้ที่การอัปเดต Gradle |
เครื่องมือสร้าง SDK |
27.0.3 |
27.0.3 |
ติดตั้งหรือกำหนดค่าเครื่องมือสร้าง SDK โปรดทราบว่าคุณไม่จำเป็นต้องระบุเวอร์ชันสำหรับเครื่องมือบิลด์โดยใช้พร็อพเพอร์ตี้ android.buildToolsVersion อีกต่อไป เนื่องจากปลั๊กอินจะใช้เวอร์ชันขั้นต่ำที่จำเป็นโดยค่าเริ่มต้น |
คอมไพเลอร์ DEX ใหม่ D8
ตอนนี้ Android Studio ใช้คอมไพเลอร์ DEX ใหม่ที่ชื่อ D8 โดยค่าเริ่มต้น การคอมไพล์ DEX
คือกระบวนการแปลงไบต์โค้ด .class
เป็นไบต์โค้ด
.dex
สำหรับ Android Runtime (หรือ Dalvik สำหรับ Android เวอร์ชันเก่า
) เมื่อเทียบกับคอมไพเลอร์ก่อนหน้าซึ่งเรียกว่า DX แล้ว D8
จะคอมไพล์ได้เร็วกว่าและเอาต์พุตเป็นไฟล์ DEX ที่มีขนาดเล็กกว่า ในขณะที่ยังคงมีประสิทธิภาพรันไทม์ของแอปเท่าเดิมหรือดีกว่า
D8 ไม่ควรเปลี่ยนเวิร์กโฟลว์การพัฒนาแอปในแต่ละวัน อย่างไรก็ตาม หากพบปัญหาที่เกี่ยวข้องกับคอมไพเลอร์ใหม่ โปรดรายงานข้อบกพร่อง คุณปิดใช้ D8 ชั่วคราวและใช้ DX ได้โดยรวมข้อความต่อไปนี้ไว้ในไฟล์ gradle.properties
ของโปรเจ็กต์
android.enableD8=false
สำหรับโปรเจ็กต์ที่
ใช้ฟีเจอร์ภาษาของ Java 8
ระบบจะเปิดใช้การแยกน้ำตาลแบบเพิ่มทีละรายการโดยค่าเริ่มต้น คุณปิดใช้ได้โดย
ระบุสิ่งต่อไปนี้ในไฟล์ gradle.properties
ของโปรเจ็กต์
android.enableIncrementalDesugaring=false.
ผู้ใช้เวอร์ชันตัวอย่าง: หากคุณใช้ D8 เวอร์ชันตัวอย่างอยู่แล้ว โปรดทราบว่า
ตอนนี้ D8 จะคอมไพล์กับไลบรารีที่รวมอยู่ใน
เครื่องมือสร้าง SDK ไม่ใช่ JDK
ดังนั้น หากคุณเข้าถึง API ที่มีอยู่ใน JDK แต่ไม่มีอยู่ในไลบรารีเครื่องมือสร้าง SDK
คุณจะได้รับข้อผิดพลาดในการคอมไพล์
การเปลี่ยนแปลงลักษณะการทำงาน
-
เมื่อสร้าง APK หลายรายการที่แต่ละรายการกำหนดเป้าหมายเป็น ABI ที่แตกต่างกัน
จะไม่สร้าง APK สำหรับ ABI ต่อไปนี้โดยค่าเริ่มต้นอีกต่อไป
mips
, mips64
และ armeabi
หากต้องการสร้าง APK ที่กำหนดเป้าหมายเป็น ABI เหล่านี้ คุณต้องใช้
NDK r16b หรือต่ำกว่า และ
ระบุ ABI ในไฟล์ build.gradle
ดังที่แสดงด้านล่าง
splits {
abi {
include 'armeabi', 'mips', 'mips64'
...
}
}
splits {
abi {
include("armeabi", "mips", "mips64")
...
}
}
-
ตอนนี้ build
cache ของปลั๊กอิน Android จะนำรายการแคชที่มีอายุมากกว่า 30 วันออก
-
การส่ง "auto"
ไปยัง
resConfig
จะไม่เลือกทรัพยากรสตริงเพื่อแพ็กเกจลงใน APK โดยอัตโนมัติอีกต่อไป
หากคุณใช้ "auto"
ต่อไป ปลั๊กอินจะแพ็กเกจสตริงทั้งหมด
ทรัพยากรที่แอปและทรัพยากร Dependency ของแอปมีให้ ดังนั้น คุณควร
ระบุภาษาแต่ละภาษาที่ต้องการให้ปลั๊กอินแพ็กเกจลงใน APK แทน
-
เนื่องจากโมดูลภายในจะขึ้นอยู่กับ APK ของการทดสอบแอปไม่ได้ การเพิ่ม
การอ้างอิงในการทดสอบที่มีการวัดโดยใช้การกำหนดค่า androidTestApi
แทน androidTestImplementation
จะทำให้ Gradle แสดงคำเตือนต่อไปนี้
WARNING: Configuration 'androidTestApi' is obsolete
and has been replaced with 'androidTestImplementation'
WARNING: Configuration 'androidTestApi' is obsolete
and has been replaced with 'androidTestImplementation'
การแก้ไข
- แก้ไขปัญหาที่ Android Studio ไม่รู้จัก
การขึ้นต่อกันในการสร้างแบบคอมโพสิตอย่างถูกต้อง
- แก้ไขปัญหาที่คุณได้รับข้อผิดพลาดในการซิงค์โปรเจ็กต์เมื่อโหลดปลั๊กอิน Android หลายครั้งในการสร้างครั้งเดียว เช่น เมื่อโปรเจ็กต์ย่อยหลายโปรเจ็กต์แต่ละโปรเจ็กต์มีปลั๊กอิน Android ใน classpath ของ buildscript
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-09-03 UTC
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 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"]]