コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Android Gradle プラグイン 2.2.0(2016 年 9 月)
- 依存関係:
|
最小バージョン |
デフォルトのバージョン |
備考 |
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 デーモン使用時のローカル権限昇格を可能にするセキュリティ脆弱性を修正しました。詳細については、Gradle リリースノートをご覧ください。
externalNativeBuild {}
DSL を使用することで、Gradle でネイティブ ソースにリンクし、CMake や ndk-build を使用してネイティブ ライブラリをコンパイルできるようになりました。Gradle は、ネイティブ ライブラリを作成した後、APK にパッケージ化します。CMake と ndk-build を Gradle で使用する方法については、プロジェクトへの C / C++ コードの追加をご覧ください。
- コマンドラインからビルド実行すると、Gradle は不足している SDK コンポーネントやプロジェクトが依存しているアップデートの自動ダウンロードを試みます。
詳細については、不足しているパッケージの Gradle での自動ダウンロードをご覧ください。
- 新しい試験運用版のキャッシュ機能により、Gradle では、pre-dex をかけ、保存し、pre-dex がかけられたバージョンのライブラリを再利用することで、ビルド時間を短縮できます。この試験運用版機能の使用方法について詳しくは、ビルド キャッシュのガイドをご覧ください。
- 圧縮、署名、zipalign を 1 つのタスクで処理する新しいデフォルトのパッケージ化パイプラインを採用することで、ビルドのパフォーマンスを改善しました。
gradle.properties
ファイルに android.useOldPackaging=true
を追加すると、以前のパッケージ化ツールを使用するように戻せます。新しいパッケージ化ツールの使用中、zipalignDebug
タスクは使用できません。ただし、createZipAlignTask(String taskName, File inputFile, File
outputFile)
メソッドを呼び出すことで、独自に作成できます。
- APK 署名では、従来の JAR 署名に加えて APK 署名スキーム v2 が使用されるようになりました。生成される APK は、すべての Android プラットフォームで受け入れられます。署名後にこれらの APK を変更すると、v2 署名が無効になり、デバイスへのインストールができなくなります。この機能を無効にするには、モジュール レベルの
build.gradle
ファイルに次のコードを追加します。
Groovy
android {
...
signingConfigs {
config {
...
v2SigningEnabled false
}
}
}
Kotlin
android {
...
signingConfigs {
create("config") {
...
v2SigningEnabled = false
}
}
}
- Multidex ビルドでは、ProGuard ルールを使用して、Gradle でアプリのメインの DEX ファイルにコンパイルする必要があるクラスを決定できるようになりました。Android システムはアプリの起動時にメインの DEX ファイルを最初に読み込むため、特定のクラスをメインの DEX ファイルにコンパイルすることで、起動時に優先順位を付けられます。メインの DEX ファイル専用の ProGuard 設定ファイルを作成してから、
buildTypes.multiDexKeepProguard
を使用して、設定ファイルのパスを Gradle に渡します。この DSL の使用は、アプリの一般的な ProGuard ルールを提供しメイン DEX ファイルのクラスを指定しない buildTypes.proguardFiles
の使用とは異なります。
- デバイスにインストールするときにアプリのサイズを小さくできる
android:extractNativeLibs
フラグのサポートを追加しました。アプリのマニフェストの <application>
要素でこのフラグを false
に設定すると、Gradle は圧縮されていないバージョンと調整されたバージョンのネイティブ ライブラリを APK にパッケージ化します。PackageManager
がインストール時に APK からデバイスのファイル システムにネイティブ ライブラリをコピーできなくなり、アプリの差分アップデートを小さくできるというメリットもあります。
- プロダクト フレーバーに
versionNameSuffix
と applicationIdSuffix
を指定できるようになりました(問題 #59614)。
-
変更内容:
-
getDefaultProguardFile
は、Android Plugin for Gradle が提供するデフォルトの ProGuard ファイルを返すようになり、Android SDK のファイルを使用しなくなりました。
- Jack コンパイラのパフォーマンスと機能を改善しました:
testCoverageEnabled
を true
に設定すると、Jack で Jacoco テスト カバレッジがサポートされるようになりました。
- アノテーション プロセッサのサポートを改善しました。
compile
依存関係など、クラスパス上のアノテーション プロセッサは、ビルドに自動的に適用されます。ビルドでアノテーション プロセッサを指定し、モジュール レベルの build.gradle
ファイルで javaCompileOptions.annotationProcessorOptions {}
DSL を使用して引数を渡すこともできます。
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 GB 以上の場合、Jack はデフォルトで Gradle と同じプロセスで実行されるようになりました。デーモンのヒープサイズを調整するには、
gradle.properties
ファイルに次の行を追加します。
# This sets the daemon heap size to 1.5GB.
org.gradle.jvmargs=-Xmx1536M
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-08-30 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-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"]]