【Plugin DSL】Android Gradle Plugin のバージョンを調べる方法

Google Maven Repository では公開されているバージョンは分かりますが。

【Plugin DSL】Android Gradle Plugin のバージョンはどこに記述するのか

👉 Google's Maven Repository hatena-bookmark

Plugin DSLVersion Catalogtoml を使うと、今現在安定版の Android Studio 上ではうまく表示されないようです。

Android Gradle Plugin

レガシーな記述では、build.gradle の以下の* 部分に記述されていました。


// build.gradle (root)

buildscript {
  repositories {
    gradlePluginPortal()
    google()
    mavenCentral()
  }

  dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1' // *
    classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.41'
  }
}


// app/build.gradle (module)

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

一方、 Plugin DSL では、Plugin Marker Artifacts を利用して解決されるので、com.android.tools.build:gradle の記述は消えます。

よくある基本的な記述を以下に挙げます。


# gradle/libs.versions.toml

[versions]
agp = "7.3.1" // *
kotlin = "1.7.20"

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" } // *
android-library = { id = "com.android.library", version.ref = "agp" } // *
android-lint = { id = "com.android.lint", version.ref = "agp" }
android-test = { id = "com.android.test", version.ref = "agp" }

kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" }


// build.gradle.kts (root)

plugins {
    alias(libs.plugins.android.application) apply false
    alias(libs.plugins.android.library) apply false
    alias(libs.plugins.android.lint) apply false
    alias(libs.plugins.android.test) apply false
    alias(libs.plugins.kotlin.android) apply false
    alias(libs.plugins.kotlin.kapt) apply false
}


// app/build.gradle.kts (module)

plugins {
    alias(libs.plugins.android.application)
    alias(libs.plugins.kotlin.android)
}

この場合の、Android Gradle plugin のバージョンは、 [version]agp の値になりますので、7.3.1 ということになります。

詳しくは以前にに書きました。
👉 【Plugin DSL】「com.android.tools.build:gradle」の記述は不要? hatena-bookmark

 

■ まとめ

build.gradle


classpath 'com.android.tools.build:gradle:x.y.z'

の記述がない場合の Android Gradle Plugin のバージョンは、

以下の、どれかのプラグインID のバージョン(共通) です。


- com.android.application
- com.android.library
- com.android.lint
- com.android.test

👉 q=.gradle.plugin - Google's Maven Repository hatena-bookmark

👉 Jetpack Compose Samples でも使われている「Version catalog update plugin」で libs.versions.toml を書き出してみる hatena-bookmark

👉 【Plugin DSL】「com.android.tools.build:gradle」の記述は不要? hatena-bookmark


Google マップへ投稿すると Google Pixel 製品を 10%オフ にできる件

メールが来ました!

 おすすめ: 最新の Google Pixel 製品が 10% オフ

Google マップへの投稿のお礼として、Google Pixel 7、Google Pixel 7 Pro、Google Pixel Watch を含む Google の新製品が 10% オフになる特典をご用意しました。Google ストアに在庫があるうちに次のお買い物をして 10% オフを使いましょう。¹

また、10%引きとかwww

いつものプロモーションコードでの割引です。

Google マップへ投稿して Google Pixel 製品を 10%オフ にできる件

¹プロモーション コードによる特典は、Google 合同会社 が提供するものです。日本の Google ストアのみで利用でき、下記の利用規約が適用されます。日本国内にお住まいで、配送先住所が日本国内にある場合のみご利用いただけます。18 歳以上の方のみを対象とします。プロモーション コードは、2022 年 11 月 15 日午後 9 時 59 分(日本時間)までに日本の Google ストアでご利用ください。それまでにご利用いただけない場合は、期限切れで失効します。その他のプロモーション コードや、同時期に実施中の他の同時購入特典や割引などの特典とは併用できません。在庫がなくなり次第終了させていただきます。

Google マップに投稿しているともらえるのか。

このメッセージは、ローカルガイドからニュースやサービスの最新情報をメールで受け取るようお申し込みされた方にお送りしています。配信の停止やメール設定の変更はローカルガイドの設定ページで行うことができます。

iPhone 14 同様に売れてないのかもしれません、Pixel 7。

👉 【Google ストア公式】Pixel 7/7 PRO プロモーションコード でさらにダメ押しの 10%割引 を見逃すな - 2022年10月16日午後11時59分まで hatena-bookmark


Jetpack Compose Samples でも使われている「Version catalog update plugin」で libs.versions.toml を書き出してみる

一度は見たことがあるでしょう「Jetpack Compose Samples」。

Jetpack Compose Samples

👉 android/compose-samples: Official Jetpack Compose samples. hatena-bookmark

こんな記述があります。

👉 Jetchat/build.gradle.kts#L39-L42 hatena-bookmark

何でしょうか、調べてみましょう。

 

■ Version catalog update plugin

このプラグインは、libs.versions.toml の作成や更新をしてくれるようです。


👉 littlerobots/version-catalog-update-plugin: Gradle plugin for updating a project version catalog hatena-bookmark

一度、書き出して、どのようになるか確かめてみます。

 

■ 作成


./gradlew versionCatalogUpdate --create

作成されました。


[versions]
androidx-appcompat = "1.5.1"
androidx-arch-core = "2.1.0"
androidx-core = "1.8.0"
androidx-emoji2 = "1.2.0"
androidx-vectordrawable = "1.1.0"
org-jetbrains-kotlin = "1.7.20"
org-jetbrains-kotlinx = "1.6.1"

[libraries]
androidx-activity = "androidx.activity:activity:1.5.1"
androidx-annotation = "androidx.annotation:annotation:1.3.0"
androidx-annotation-annotation-experimental = "androidx.annotation:annotation-experimental:1.1.0"
androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "androidx-appcompat" }
androidx-appcompat-appcompat-resources = { module = "androidx.appcompat:appcompat-resources", version.ref = "androidx-appcompat" }
androidx-arch-core-core-common = { module = "androidx.arch.core:core-common", version.ref = "androidx-arch-core" }
androidx-arch-core-core-runtime = { module = "androidx.arch.core:core-runtime", version.ref = "androidx-arch-core" }
androidx-cardview = "androidx.cardview:cardview:1.0.0"
androidx-collection = "androidx.collection:collection:1.1.0"
androidx-concurrent-concurrent-futures = "androidx.concurrent:concurrent-futures:1.0.0"
androidx-constraintlayout = "androidx.constraintlayout:constraintlayout:2.1.4"
androidx-constraintlayout-constraintlayout-core = "androidx.constraintlayout:constraintlayout-core:1.0.4"
androidx-constraintlayout-constraintlayout-solver = "androidx.constraintlayout:constraintlayout-solver:2.0.1"
androidx-coordinatorlayout = "androidx.coordinatorlayout:coordinatorlayout:1.1.0"
androidx-core = { module = "androidx.core:core", version.ref = "androidx-core" }
androidx-core-core-ktx = { module = "androidx.core:core-ktx", version.ref = "androidx-core" }
androidx-cursoradapter = "androidx.cursoradapter:cursoradapter:1.0.0"
androidx-customview = "androidx.customview:customview:1.1.0"
androidx-documentfile = "androidx.documentfile:documentfile:1.0.0"
androidx-drawerlayout = "androidx.drawerlayout:drawerlayout:1.1.1"
androidx-dynamicanimation = "androidx.dynamicanimation:dynamicanimation:1.0.0"
androidx-emoji2 = { module = "androidx.emoji2:emoji2", version.ref = "androidx-emoji2" }
androidx-emoji2-emoji2-views-helper = { module = "androidx.emoji2:emoji2-views-helper", version.ref = "androidx-emoji2" }
androidx-fragment = "androidx.fragment:fragment:1.3.6"
androidx-interpolator = "androidx.interpolator:interpolator:1.0.0"
androidx-legacy-legacy-support-core-utils = "androidx.legacy:legacy-support-core-utils:1.0.0"
androidx-lifecycle-lifecycle-common = "androidx.lifecycle:lifecycle-common:2.5.1"
androidx-lifecycle-lifecycle-livedata = "androidx.lifecycle:lifecycle-livedata:2.0.0"
androidx-lifecycle-lifecycle-livedata-core = "androidx.lifecycle:lifecycle-livedata-core:2.5.1"
androidx-lifecycle-lifecycle-process = "androidx.lifecycle:lifecycle-process:2.4.1"
androidx-lifecycle-lifecycle-runtime = "androidx.lifecycle:lifecycle-runtime:2.5.1"
androidx-lifecycle-lifecycle-viewmodel = "androidx.lifecycle:lifecycle-viewmodel:2.5.1"
androidx-lifecycle-lifecycle-viewmodel-savedstate = "androidx.lifecycle:lifecycle-viewmodel-savedstate:2.5.1"
androidx-loader = "androidx.loader:loader:1.0.0"
androidx-localbroadcastmanager = "androidx.localbroadcastmanager:localbroadcastmanager:1.0.0"
androidx-print = "androidx.print:print:1.0.0"
androidx-recyclerview = "androidx.recyclerview:recyclerview:1.1.0"
androidx-resourceinspection-resourceinspection-annotation = "androidx.resourceinspection:resourceinspection-annotation:1.0.1"
androidx-savedstate = "androidx.savedstate:savedstate:1.2.0"
androidx-startup-startup-runtime = "androidx.startup:startup-runtime:1.1.1"
androidx-test-espresso-espresso-core = "androidx.test.espresso:espresso-core:3.4.0"
androidx-test-ext-junit = "androidx.test.ext:junit:1.1.3"
androidx-tracing = "androidx.tracing:tracing:1.0.0"
androidx-transition = "androidx.transition:transition:1.2.0"
androidx-vectordrawable = { module = "androidx.vectordrawable:vectordrawable", version.ref = "androidx-vectordrawable" }
androidx-vectordrawable-vectordrawable-animated = { module = "androidx.vectordrawable:vectordrawable-animated", version.ref = "androidx-vectordrawable" }
androidx-versionedparcelable = "androidx.versionedparcelable:versionedparcelable:1.1.1"
androidx-viewpager = "androidx.viewpager:viewpager:1.0.0"
androidx-viewpager2 = "androidx.viewpager2:viewpager2:1.0.0"
com-google-android-material = "com.google.android.material:material:1.7.0"
junit = "junit:junit:4.13.2"
org-apache-logging-log4j-log4j-core = "org.apache.logging.log4j:log4j-core:2.17.1"
org-jacoco-org-jacoco-ant = "org.jacoco:org.jacoco.ant:0.8.7"
org-jetbrains-annotations = "org.jetbrains:annotations:13.0"
org-jetbrains-kotlin-kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "org-jetbrains-kotlin" }
org-jetbrains-kotlin-kotlin-stdlib-common = { module = "org.jetbrains.kotlin:kotlin-stdlib-common", version.ref = "org-jetbrains-kotlin" }
org-jetbrains-kotlin-kotlin-stdlib-jdk7 = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk7", version.ref = "org-jetbrains-kotlin" }
org-jetbrains-kotlin-kotlin-stdlib-jdk8 = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "org-jetbrains-kotlin" }
org-jetbrains-kotlinx-kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "org-jetbrains-kotlinx" }
org-jetbrains-kotlinx-kotlinx-coroutines-bom = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-bom", version.ref = "org-jetbrains-kotlinx" }
org-jetbrains-kotlinx-kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "org-jetbrains-kotlinx" }
org-jetbrains-kotlinx-kotlinx-coroutines-core-jvm = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm", version.ref = "org-jetbrains-kotlinx" }

[plugins]
com-android-application = "com.android.application:7.3.1"
com-android-library = "com.android.library:7.3.1"
com-github-ben-manes-versions = "com.github.ben-manes.versions:0.41.0"
nl-littlerobots-version-catalog-update = "nl.littlerobots.version-catalog-update:0.7.0"
org-jetbrains-kotlin-android = "org.jetbrains.kotlin.android:1.7.20"

フォーマットが統一され、ソートされたきれいなTOMLファイルです。

キーは、kebab-case で重複処理も上手に行ってくれてるように見えます。

👉 【Gradle Version Catalog】libs.versions.toml キー名の形式 camelCase vs kebab-case hatena-bookmark

build.gradle 側は更新しないようなので新規作成は安全ですが、既存の場合は、


./gradlew versionCatalogUpdate --interactive

とすると、別のファイル名 libs.versions.updates.toml で書き出してくれるようです。

Version catalog update plugin

実行後は gradle ディレクトリを Reload すると作成されてることが確認できます。


[plugins]
# From version 7.3.1 --> 8.0.0-alpha06
android-application = "com.android.application:8.0.0-alpha06"

まずは、参考にまで使ってみました。簡単で便利です。

無駄のない最小限の記述なので、最初の書き出しには使うと良いと思います。

👌 もっと、シンプルでいいような気がするので以下の方法でもやってみました。


👉 「⚠ This project uses Gradle Version Catalogs: this tool may not behave as expected.」→ 今現在、Gradle Version Catalog には gradle-versions-plugin が必須では? hatena-bookmark