קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
Android Gradle Plugin 2.2.0 (ספטמבר 2016)
- תלויות:
|
גרסת מינימום |
גרסת ברירת המחדל |
הערות |
Gradle |
2.14.1 |
2.14.1 |
יש מידע נוסף במאמר בנושא עדכון Gradle. |
SDK Build Tools |
23.0.2 |
23.0.2 |
התקנה או הגדרה של SDK Build Tools. |
- המינוי החדש:
-
- הגרסה הזו משתמשת ב-Gradle 2.14.1, שכוללת שיפורים בביצועים ותכונות חדשות, ומתקנת פגיעות באבטחה שמאפשרת העלאת הרשאות מקומיות כשמשתמשים ב-Gradle daemon. פרטים נוספים זמינים ב
הערות המוצר של Gradle.
- באמצעות
externalNativeBuild {}
DSL, Gradle מאפשר עכשיו לקשר למקורות המקוריים ולבצע קומפילציה של ספריות מקוריות באמצעות CMake או ndk-build. אחרי שיוצרים את הספריות המקוריות, Gradle אורז אותן ב-APK. מידע נוסף על שימוש ב-CMake וב-ndk-build עם Gradle זמין במאמר הוספת קוד C ו-C++ לפרויקט.
- כשמריצים בנייה משורת הפקודה, Gradle מנסה עכשיו להוריד באופן אוטומטי רכיבי SDK חסרים או עדכונים שהפרויקט תלוי בהם.
מידע נוסף על הורדה אוטומטית של חבילות חסרות באמצעות Gradle
- תכונה חדשה של שמירת נתונים במטמון מאפשרת ל-Gradle להאיץ את זמני הבנייה באמצעות dexing מראש, אחסון ושימוש חוזר בגרסאות של הספריות שעברו dexing מראש. במדריך Build Cache מוסבר איך משתמשים בתכונה הניסיונית הזו.
- שיפור הביצועים של תהליך הבנייה באמצעות אימוץ צינור אריזה חדש שמוגדר כברירת מחדל, שמטפל בדחיסה, בחתימה וביישור זיפ במשימה אחת. אפשר לחזור להשתמש בכלי האריזה הישנים יותר על ידי הוספת
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
ברמת המודול:
android {
...
signingConfigs {
config {
...
v2SigningEnabled false
}
}
}
android {
...
signingConfigs {
create("config") {
...
v2SigningEnabled = false
}
}
}
- בגרסאות build של multidex, אפשר עכשיו להשתמש בכללי ProGuard כדי לקבוע אילו מחלקות Gradle צריך לקמפל לקובץ הראשי של DEX באפליקציה. מערכת Android טוענת קודם את קובץ ה-DEX הראשי כשמפעילים את האפליקציה, ולכן אפשר לתת עדיפות למחלקות מסוימות בהפעלה על ידי קומפילציה שלהן לקובץ ה-DEX הראשי. אחרי שיוצרים קובץ הגדרות של ProGuard במיוחד בשביל קובץ ה-DEX הראשי, מעבירים את הנתיב של קובץ ההגדרות אל Gradle באמצעות
buildTypes.multiDexKeepProguard
. השימוש ב-DSL הזה שונה מהשימוש ב-
buildTypes.proguardFiles
, שכולל כללי ProGuard כלליים לאפליקציה ולא מציין מחלקות לקובץ ה-DEX הראשי.
- נוסף תמיכה בדגל
android:extractNativeLibs
,
שיכול לצמצם את גודל האפליקציה כשמתקינים אותה במכשיר. כשמגדירים את הדגל הזה לערך false
באלמנט
<application>
של קובץ המניפסט של האפליקציה, Gradle אורז גרסאות לא דחוסות ומיושרות של ספריות Native עם ה-APK. כך PackageManager
לא מעתיק את הספריות המקוריות מקובץ ה-APK למערכת הקבצים של המכשיר במהלך ההתקנה, וגם גודל העדכונים של האפליקציה קטן יותר.
- עכשיו אפשר לציין
versionNameSuffix
ו-
applicationIdSuffix
לטעמים של מוצרים. (בעיה מספר 59614)
-
שינויים:
-
-
getDefaultProguardFile
מחזירה עכשיו את קובצי ברירת המחדל של ProGuard שפלאגין Android ל-Gradle מספק, ולא משתמשת יותר בקובצים שב-Android SDK.
- שיפורים בביצועים ובתכונות של מהדר Jack:
- Jack תומך עכשיו בכיסוי בדיקות של Jacoco כשמגדירים את
testCoverageEnabled
ל-true
.
- תמיכה משופרת במעבדי הערות. מעבדי הערות (annotation) בנתיב המחלקות (classpath), כמו תלות (dependencies) ב-
compile
, מוחלים אוטומטית על הבנייה. אפשר גם לציין מעבד הערות ב-build ולהעביר ארגומנטים באמצעות ה-DSL
javaCompileOptions.annotationProcessorOptions {}
בקובץ build.gradle
ברמת המודול:
android {
...
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
className 'com.example.MyProcessor'
// Arguments are optional.
arguments = [ foo : 'bar' ]
}
}
}
}
android {
...
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
className = "com.example.MyProcessor"
// Arguments are optional.
arguments(mapOf(foo to "bar"))
}
}
}
}
אם רוצים להחיל מעבד הערות בזמן ההידור, אבל לא לכלול אותו בחבילת ה-APK, צריך להשתמש בannotationProcessor
היקף התלות:
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
}
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
- כברירת מחדל, אם גודל ה-heap של Gradle daemon הוא לפחות 1.5GB, 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"]]