จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ปลั๊กอิน Android Gradle 2.2.0 (กันยายน 2016)
- การขึ้นต่อกัน
|
เวอร์ชันขั้นต่ำ |
เวอร์ชันเริ่มต้น |
หมายเหตุ |
Gradle |
2.14.1 |
2.14.1 |
ดูข้อมูลเพิ่มเติมได้ที่การอัปเดต Gradle |
เครื่องมือสร้าง SDK |
23.0.2 |
23.0.2 |
ติดตั้งหรือกำหนดค่าเครื่องมือสร้าง SDK |
- ใหม่:
-
- ใช้ Gradle 2.14.1 ซึ่งมีการปรับปรุงประสิทธิภาพ
และฟีเจอร์ใหม่ รวมถึงแก้ไขช่องโหว่ด้านความปลอดภัยที่อนุญาต
การเพิ่มสิทธิ์ในเครื่องเมื่อใช้ Gradle Daemon ดูรายละเอียดเพิ่มเติมได้ที่
บันทึกประจำรุ่นของ Gradle
- ตอนนี้ Gradle ช่วยให้คุณลิงก์กับแหล่งที่มาแบบเนทีฟและคอมไพล์ไลบรารีแบบเนทีฟได้โดยใช้ CMake หรือ ndk-build โดยใช้ DSL
externalNativeBuild {}
หลังจากสร้างไลบรารีแบบเนทีฟแล้ว Gradle จะแพ็กเกจไลบรารีเหล่านั้นลงใน APK ดูข้อมูลเพิ่มเติมเกี่ยวกับการใช้ CMake และ
ndk-build กับ Gradle ได้ที่เพิ่มโค้ด C และ C++ ลงใน
โปรเจ็กต์
- เมื่อคุณเรียกใช้
บิลด์จากบรรทัดคำสั่ง ตอนนี้ Gradle จะพยายามดาวน์โหลด
คอมโพเนนต์ SDK ที่ขาดหายไปหรือการอัปเดตที่โปรเจ็กต์ของคุณต้องใช้โดยอัตโนมัติ
ดูข้อมูลเพิ่มเติมได้ที่ดาวน์โหลดแพ็กเกจที่ขาดหายไปโดยอัตโนมัติ
ด้วย Gradle
- ฟีเจอร์แคชเวอร์ชันทดลองใหม่ช่วยให้ Gradle เร่งเวลาบิลด์ได้โดยการ
ดำเนินการ dex ล่วงหน้า จัดเก็บ และนำเวอร์ชันที่ดำเนินการ dex ล่วงหน้าของ
ไลบรารีกลับมาใช้ใหม่ ดูข้อมูลเพิ่มเติมเกี่ยวกับการใช้ฟีเจอร์ทดลองนี้ได้ในคำแนะนำสร้าง
แคช
- ปรับปรุงประสิทธิภาพการสร้างโดยใช้ไปป์ไลน์การแพ็กเกจเริ่มต้นใหม่
ซึ่งจัดการการซิป การลงนาม และzipalign ในงานเดียว คุณ
สามารถกลับไปใช้เครื่องมือการแพ็กเกจเวอร์ชันเก่าได้โดยเพิ่ม
android.useOldPackaging=true
ลงในไฟล์
gradle.properties
ขณะใช้เครื่องมือการแพ็กเกจแบบใหม่
คุณจะใช้zipalignDebug
ไม่ได้ อย่างไรก็ตาม
คุณสามารถสร้างเองได้โดยเรียกใช้เมธอด
createZipAlignTask(String taskName, File inputFile, File
outputFile)
- ตอนนี้การรับรอง APK ใช้ APK Signature Scheme
v2 นอกเหนือจากการรับรอง JAR แบบเดิม แพลตฟอร์ม Android ทั้งหมดยอมรับ APK ที่ได้ การแก้ไข APK เหล่านี้หลังจากลงนามจะทำให้ลายเซ็น v2 ใช้งานไม่ได้และป้องกันการติดตั้งในอุปกรณ์
หากต้องการปิดใช้ฟีเจอร์นี้
ให้เพิ่มโค้ดต่อไปนี้ลงในไฟล์
build.gradle
ระดับโมดูล
Groovy
android {
...
signingConfigs {
config {
...
v2SigningEnabled false
}
}
}
Kotlin
android {
...
signingConfigs {
create("config") {
...
v2SigningEnabled = false
}
}
}
- สำหรับการสร้าง Multidex ตอนนี้คุณสามารถใช้กฎ ProGuard เพื่อกำหนดคลาสที่ Gradle ควรคอมไพล์ลงในไฟล์ DEX main ของแอปได้แล้ว เนื่องจาก
ระบบ Android จะโหลดไฟล์ DEX หลักก่อนเมื่อเริ่มต้นแอป คุณ
จึงจัดลำดับความสำคัญของบางคลาสเมื่อเริ่มต้นได้โดยคอมไพล์คลาสเหล่านั้นลงในไฟล์ DEX หลัก
หลังจากสร้างไฟล์การกำหนดค่า ProGuard สำหรับ
ไฟล์ DEX หลักโดยเฉพาะแล้ว ให้ส่งเส้นทางของไฟล์การกำหนดค่าไปยัง Gradle โดยใช้
buildTypes.multiDexKeepProguard
การใช้ DSL นี้แตกต่าง
จากการใช้
buildTypes.proguardFiles
ซึ่งมีกฎ ProGuard ทั่วไป
สำหรับแอปและไม่ได้ระบุคลาสสำหรับไฟล์ DEX หลัก
- เพิ่มการรองรับแฟล็ก
android:extractNativeLibs
ซึ่งจะช่วยลดขนาดของแอปเมื่อติดตั้งใน
อุปกรณ์ เมื่อตั้งค่าแฟล็กนี้เป็น false
ในองค์ประกอบ
<application>
ของไฟล์ Manifest ของแอป Gradle จะแพ็กเกจไลบรารีแบบเนทีฟเวอร์ชันที่ไม่ได้บีบอัดและ
จัดแนวไว้กับ APK ซึ่งจะป้องกันไม่ให้ PackageManager
คัดลอกไลบรารีแบบเนทีฟจาก APK ไปยังระบบไฟล์ของอุปกรณ์ในระหว่างการติดตั้ง และยังช่วยให้การอัปเดตเดลต้าของแอปมีขนาดเล็กลงอีกด้วย
- ตอนนี้คุณระบุ
versionNameSuffix
และ
applicationIdSuffix
สำหรับรสชาติของผลิตภัณฑ์ได้แล้ว (ปัญหา 59614)
-
การเปลี่ยนแปลง:
-
-
getDefaultProguardFile
จะแสดงไฟล์ ProGuard เริ่มต้น
ที่ปลั๊กอิน Android สำหรับ Gradle จัดเตรียมให้ และจะไม่ใช้
ไฟล์ใน Android SDK อีกต่อไป
- ปรับปรุงประสิทธิภาพและฟีเจอร์ของคอมไพเลอร์ Jack ดังนี้
- ตอนนี้ Jack รองรับความครอบคลุมของการทดสอบ Jacoco เมื่อตั้งค่า
testCoverageEnabled
เป็น true
แล้ว
- ปรับปรุงการรองรับสำหรับโปรเซสเซอร์คำอธิบายประกอบ ระบบจะใช้ตัวประมวลผล
คำอธิบายประกอบใน Classpath เช่น การขึ้นต่อกันของ
compile
โดยอัตโนมัติกับการสร้าง คุณยังระบุตัวประมวลผลคำอธิบายประกอบในการสร้างและส่งอาร์กิวเมนต์ได้โดยใช้ DSL
javaCompileOptions.annotationProcessorOptions {}
ในไฟล์ระดับโมดูล build.gradle
Groovy
android {
...
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
className 'com.example.MyProcessor'
// Arguments are optional.
arguments = [ foo : 'bar' ]
}
}
}
}
Kotlin
android {
...
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
className = "com.example.MyProcessor"
// Arguments are optional.
arguments(mapOf(foo to "bar"))
}
}
}
}
หากต้องการใช้ตัวประมวลผลคำอธิบายประกอบในเวลาคอมไพล์
แต่ไม่รวมไว้ใน APK ให้ใช้
annotationProcessor
ขอบเขตการขึ้นต่อกัน
Groovy
dependencies {
compile 'com.google.dagger:dagger:2.0'
annotationProcessor 'com.google.dagger:dagger-compiler:2.0'
// or use buildVariantAnnotationProcessor to target a specific build variant
}
Kotlin
dependencies {
implementation("com.google.dagger:dagger:2.0")
annotationProcessor("com.google.dagger:dagger-compiler:2.0")
// or use buildVariantAnnotationProcessor to target a specific build variant
}
หากต้องการดูรายการพารามิเตอร์ที่ตั้งค่าได้ ให้เรียกใช้คำสั่งต่อไปนี้จากบรรทัดคำสั่ง
java -jar /build-tools/jack.jar --help-properties
- โดยค่าเริ่มต้น หากขนาดฮีปของ Gradle Daemon มีขนาดอย่างน้อย 1.5
GB ตอนนี้ Jack จะทำงานในกระบวนการเดียวกับ Gradle หากต้องการปรับ
ขนาดฮีปของ Daemon ให้เพิ่มข้อมูลต่อไปนี้ลงในไฟล์
gradle.properties
# This sets the daemon heap size to 1.5GB.
org.gradle.jvmargs=-Xmx1536M
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-30 UTC
[null,null,["อัปเดตล่าสุด 2025-08-30 UTC"],[],[],null,["\u003cbr /\u003e\n\nAndroid Gradle Plugin 2.2.0 (September 2016)\n\nDependencies:\nNew:\n:\n - Uses Gradle 2.14.1, which includes performance improvements and new features, and fixes a security vulnerability that allows local privilege escalation when using the Gradle daemon. For more details, see the [Gradle release notes](https://docs.gradle.org/2.14.1/release-notes).\n - Using the [`externalNativeBuild {}`](https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.ExternalNativeBuild.html) DSL, Gradle now lets you link to your native sources and compile native libraries using CMake or ndk-build. After building your native libraries, Gradle packages them into your APK. To learn more about using CMake and ndk-build with Gradle, read [Add C and C++ Code to Your\n Project](/studio/projects/add-native-code).\n - When you [run a\n build from the command line](/studio/build/building-cmdline), Gradle now attempts to auto-download any missing SDK components or updates that your project depends on. To learn more, read [Auto-download\n missing packages with Gradle](/studio/intro/update#download-with-gradle).\n - A new experimental caching feature lets Gradle speed up build times by pre-dexing, storing, and reusing the pre-dexed versions of your libraries. To learn more about using this experimental feature, read the [Build\n Cache](/studio/build/build-cache) guide.\n - Improves build performance by adopting a new default packaging pipeline which handles zipping, signing, and [zipaligning](/studio/command-line/zipalign) in one task. You can revert to using the older packaging tools by adding `android.useOldPackaging=true` to your `gradle.properties` file. While using the new packaging tool, the `zipalignDebug` task is not available. However, you can create one yourself by calling the `createZipAlignTask(String taskName, File inputFile, File\n outputFile)` method.\n - APK signing now uses [APK Signature Scheme\n v2](/about/versions/nougat/android-7.0#apk_signature_v2) in addition to traditional JAR signing. All Android platforms accept the resulting APKs. Any modification to these APKs after signing invalidates their v2 signatures and prevents installation on a device. To disable this feature, add the following to your module-level `build.gradle` file: \n\n Groovy \n\n ```groovy\n android {\n ...\n signingConfigs {\n config {\n ...\n v2SigningEnabled false\n }\n }\n }\n \n ```\n\n Kotlin \n\n ```kotlin\n android {\n ...\n signingConfigs {\n create(\"config\") {\n ...\n v2SigningEnabled = false\n }\n }\n }\n \n ```\n - For multidex builds, you can now use ProGuard rules to determine which classes Gradle should compile into your app's *main* DEX file. Because the Android system loads the main DEX file first when starting your app, you can prioritize certain classes at startup by compiling them into the main DEX file. After you create a ProGuard configuration file specifically for your main DEX file, pass the configuration file's path to Gradle using [buildTypes.multiDexKeepProguard](https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.BuildType.html#com.android.build.gradle.internal.dsl.BuildType:multiDexKeepProguard). Using this DSL is different from using [`buildTypes.proguardFiles`](https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.BuildType.html#com.android.build.gradle.internal.dsl.BuildType:proguardFiles(java.lang.Object[])), which provides general ProGuard rules for your app and does not specify classes for the main DEX file.\n - Adds support for the `android:extractNativeLibs` flag, which can reduce the size of your app when you install it on a device. When you set this flag to `false` in the [`\u003capplication\u003e`](/guide/topics/manifest/application-element) element of your app manifest, Gradle packages uncompressed and aligned versions of your native libraries with your APK. This prevents [`PackageManager`](/reference/android/content/pm/PackageManager) from copying out your native libraries from the APK to the device's file system during installation and has the added benefit of making delta updates of your app smaller.\n - You can now specify [`versionNameSuffix`](https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.ProductFlavor.html#com.android.build.gradle.internal.dsl.ProductFlavor:versionNameSuffix) and [`applicationIdSuffix`](https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.ProductFlavor.html#com.android.build.gradle.internal.dsl.ProductFlavor:applicationIdSuffix) for product flavors. ([Issue 59614](http://b.android.com/59614))\n\n\nChanges:\n:\n - `getDefaultProguardFile` now returns the default ProGuard files that Android plugin for Gradle provides and no longer uses the ones in the Android SDK.\n - Improved Jack compiler performance and features:\n - Jack now supports Jacoco test coverage when setting [testCoverageEnabled](https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.BuildType.html#com.android.build.gradle.internal.dsl.BuildType:testCoverageEnabled) to `true`.\n - Improved support for annotation processors. Annotation processors on your classpath, such as any `compile` dependencies, are automatically applied to your build. You can also specify an annotation processor in your build and pass arguments by using the [`javaCompileOptions.annotationProcessorOptions {}`](https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.AnnotationProcessorOptions.html) DSL in your module-level `build.gradle` file: \n\n Groovy \n\n ```groovy\n android {\n ...\n defaultConfig {\n ...\n javaCompileOptions {\n annotationProcessorOptions {\n className 'com.example.MyProcessor'\n // Arguments are optional.\n arguments = [ foo : 'bar' ]\n }\n }\n }\n }\n \n ```\n\n Kotlin \n\n ```kotlin\n android {\n ...\n defaultConfig {\n ...\n javaCompileOptions {\n annotationProcessorOptions {\n className = \"com.example.MyProcessor\"\n // Arguments are optional.\n arguments(mapOf(foo to \"bar\"))\n }\n }\n }\n }\n \n ```\n\n\n If you want to apply an annotation processor at compile\n time but not include it in your APK, use the\n `annotationProcessor` dependency scope: \n\n Groovy \n\n ```groovy\n dependencies {\n compile 'com.google.dagger:dagger:2.0'\n annotationProcessor 'com.google.dagger:dagger-compiler:2.0'\n // or use buildVariantAnnotationProcessor to target a specific build variant\n }\n \n ```\n\n Kotlin \n\n ```kotlin\n dependencies {\n implementation(\"com.google.dagger:dagger:2.0\")\n annotationProcessor(\"com.google.dagger:dagger-compiler:2.0\")\n // or use buildVariantAnnotationProcessor to target a specific build variant\n }\n \n ```\n - For a list of parameters you can set, run the following from the command line: \n\n ```\n java -jar /build-tools/jack.jar --help-properties\n ```\n - By default, if the Gradle daemon's heap size is at least 1.5 GB, Jack now runs in the same process as Gradle. To adjust the daemon heap size, add the following to your `gradle.properties` file:\n\n \u003cbr /\u003e\n\n ```\n # This sets the daemon heap size to 1.5GB.\n org.gradle.jvmargs=-Xmx1536M\n ```\n\n \u003cbr /\u003e\n\n\n\u003cbr /\u003e"]]