संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
Android Gradle प्लग इन 2.2.0 (सितंबर 2016)
- डिपेंडेंसी:
- नया:
-
- Gradle 2.14.1 का इस्तेमाल करता है. इसमें परफ़ॉर्मेंस से जुड़े सुधार और नई सुविधाएं शामिल हैं. साथ ही, इसमें सुरक्षा से जुड़ी एक ऐसी समस्या को ठीक किया गया है जिसकी वजह से Gradle डेमॉन का इस्तेमाल करते समय, स्थानीय विशेषाधिकारों को बढ़ाया जा सकता है. ज़्यादा जानकारी के लिए,
Gradle के रिलीज़ नोट देखें.
-
externalNativeBuild {}
डीएसएल का इस्तेमाल करके, Gradle अब आपको अपने नेटिव सोर्स से लिंक करने और CMake या ndk-build का इस्तेमाल करके नेटिव लाइब्रेरी कंपाइल करने की सुविधा देता है. नेटिव लाइब्रेरी बनाने के बाद, Gradle उन्हें आपके APK में पैकेज करता है. Gradle के साथ CMake और ndk-build का इस्तेमाल करने के बारे में ज़्यादा जानने के लिए, अपने प्रोजेक्ट में C और C++ कोड जोड़ना लेख पढ़ें.
- कमांड लाइन से बिल्ड चलाने पर, Gradle अब उन सभी एसडीके कॉम्पोनेंट या अपडेट को अपने-आप डाउनलोड करने की कोशिश करता है जिन पर आपका प्रोजेक्ट निर्भर करता है.
ज़्यादा जानने के लिए, Gradle की मदद से, मौजूद नहीं हैं ऐसे पैकेज अपने-आप डाउनलोड होने की सुविधा लेख पढ़ें.
- कैशिंग की नई एक्सपेरिमेंटल सुविधा की मदद से, Gradle को बिल्ड करने में लगने वाले समय को कम किया जा सकता है. इसके लिए, यह सुविधा आपकी लाइब्रेरी के प्री-डेक्स्ड वर्शन को पहले से ही डेक्स कर लेती है, उन्हें सेव करती है, और उनका फिर से इस्तेमाल करती है. एक्सपेरिमेंट के तौर पर उपलब्ध इस सुविधा के इस्तेमाल के बारे में ज़्यादा जानने के लिए, बिल्ड
कैश गाइड पढ़ें.
- यह नई डिफ़ॉल्ट पैकेजिंग पाइपलाइन का इस्तेमाल करके, बिल्ड की परफ़ॉर्मेंस को बेहतर बनाता है. यह पाइपलाइन, एक ही टास्क में ज़िप करने, हस्ताक्षर करने, और ज़िपलाइनिंग को मैनेज करती है.
gradle.properties
फ़ाइल में android.useOldPackaging=true
जोड़कर, पैकेजिंग के पुराने टूल का इस्तेमाल किया जा सकता है. नए पैकेजिंग टूल का इस्तेमाल करते समय, zipalignDebug
टास्क उपलब्ध नहीं होता. हालांकि, createZipAlignTask(String taskName, File inputFile, File
outputFile)
तरीके को कॉल करके, खुद से एक बनाया जा सकता है.
- अब APK साइन करने के लिए, JAR साइन करने के साथ-साथ APK सिग्नेचर स्कीम v2 का भी इस्तेमाल किया जाता है. सभी Android प्लैटफ़ॉर्म, जनरेट किए गए APK स्वीकार करते हैं. साइन करने के बाद, इन APK में कोई भी बदलाव करने से, इनके v2 सिग्नेचर अमान्य हो जाते हैं. साथ ही, इन्हें किसी डिवाइस पर इंस्टॉल नहीं किया जा सकता. इस सुविधा को बंद करने के लिए,
मॉड्यूल-लेवल की
build.gradle
फ़ाइल में यह कोड जोड़ें:
Groovy
android {
...
signingConfigs {
config {
...
v2SigningEnabled false
}
}
}
Kotlin
android {
...
signingConfigs {
create("config") {
...
v2SigningEnabled = false
}
}
}
- मल्टीडेक्स बिल्ड के लिए, अब ProGuard के नियमों का इस्तेमाल किया जा सकता है. इससे यह तय किया जा सकता है कि Gradle को आपके ऐप्लिकेशन की main DEX फ़ाइल में किन क्लास को कंपाइल करना चाहिए. ऐसा इसलिए होता है, क्योंकि Android सिस्टम आपके ऐप्लिकेशन को शुरू करते समय, सबसे पहले मुख्य DEX फ़ाइल लोड करता है. इसलिए, मुख्य DEX फ़ाइल में कंपाइल करके, स्टार्टअप के दौरान कुछ क्लास को प्राथमिकता दी जा सकती है. अपनी मुख्य DEX फ़ाइल के लिए ProGuard कॉन्फ़िगरेशन फ़ाइल बनाने के बाद,
buildTypes.multiDexKeepProguard
का इस्तेमाल करके, कॉन्फ़िगरेशन फ़ाइल का पाथ Gradle को पास करें. इस डीएसएल का इस्तेमाल करना,
buildTypes.proguardFiles
का इस्तेमाल करने से अलग है. buildTypes.proguardFiles
आपके ऐप्लिकेशन के लिए ProGuard के सामान्य नियम उपलब्ध कराता है. साथ ही, यह मुख्य DEX फ़ाइल के लिए क्लास तय नहीं करता है.
android:extractNativeLibs
फ़्लैग के लिए सहायता जोड़ता है. इससे किसी डिवाइस पर ऐप्लिकेशन इंस्टॉल करते समय, उसका साइज़ कम किया जा सकता है. जब ऐप्लिकेशन मेनिफ़ेस्ट के <application>
एलिमेंट में इस फ़्लैग को false
पर सेट किया जाता है, तब Gradle, आपकी नेटिव लाइब्रेरी के बिना कंप्रेस किए गए और अलाइन किए गए वर्शन को आपके APK के साथ पैकेज करता है. इससे PackageManager
को, इंस्टॉल करने के दौरान APK से डिवाइस के फ़ाइल सिस्टम में आपकी नेटिव लाइब्रेरी कॉपी करने से रोका जा सकता है. साथ ही, इससे आपके ऐप्लिकेशन के डेल्टा अपडेट का साइज़ कम हो जाता है.
- अब प्रॉडक्ट के फ़्लेवर के लिए,
versionNameSuffix
और
applicationIdSuffix
एट्रिब्यूट की वैल्यू दी जा सकती है. (समस्या 59614)
-
बदलाव:
-
-
getDefaultProguardFile
अब ProGuard की डिफ़ॉल्ट फ़ाइलें दिखाता है. ये फ़ाइलें, Gradle के लिए Android प्लगिन उपलब्ध कराता है. अब यह Android SDK में मौजूद फ़ाइलों का इस्तेमाल नहीं करता.
- Jack कंपाइलर की परफ़ॉर्मेंस और सुविधाओं में सुधार किया गया है:
- Jack अब Jacoco टेस्ट कवरेज के साथ काम करता है. इसके लिए,
testCoverageEnabled
को true
पर सेट करना होगा.
- एनोटेशन प्रोसेसर के लिए बेहतर सहायता. आपके क्लासपाथ पर मौजूद एनोटेशन प्रोसेसर, जैसे कि कोई भी
compile
डिपेंडेंसी, आपके बिल्ड पर अपने-आप लागू हो जाती हैं. अपने बिल्ड में एनोटेशन प्रोसेसर भी तय किया जा सकता है. साथ ही, मॉड्यूल-लेवल की build.gradle
फ़ाइल में
javaCompileOptions.annotationProcessorOptions {}
डीएसएल का इस्तेमाल करके, आर्ग्युमेंट पास किए जा सकते हैं:
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 डेमॉन का हीप साइज़ कम से कम 1.5 जीबी है, तो Jack अब Gradle की तरह ही प्रोसेस में चलता है. डेमॉन के हीप साइज़ में बदलाव करने के लिए, अपनी
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"]]