mcpField
A
android-gradle-logic

android-gradle-logic

github.com/new-silvermoon開発992716 回インストール13 週間前に更新
リポジトリ

android-gradle-logic について

Android プロジェクトの Gradle ビルドロジックとコンベンションプラグインの構成ガイドです。拡張しやすいビルドシステムを整える開発者向けに、build-logic と Version Catalog で設定を再利用します。

主な機能

  1. 01build-logic の複合ビルド設定
  2. 02Version Catalog によるバージョン管理
  3. 03再利用可能なコンベンションプラグインの作成
  4. 04Compose や Kotlin のビルド設定を集約
  5. 05モジュールへのカスタムプラグイン適用

活用シーン

  1. 01モジュールのビルド設定の重複を削減
  2. 02Android プラグイン設定を一元管理
  3. 03複数モジュールでビルド規約を再利用

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/new-silvermoon/awesome-android-agent-skills --skill android-gradle-logic

インストール後、Claude Code で/android-gradle-logicを入力して読み込まれたか確認します。

詳細

Android Gradle ビルドロジックと規約プラグイン

このスキルでは、Gradle 規約プラグインとバージョンカタログを使用して、「Now in Android」(NiA)のアーキテクチャに沿った、スケーラブルで保守しやすい Android アプリのビルドシステムを構成します。

目標

build.gradle.kts ファイル間でコードをコピー&ペーストするのをやめましょう。ビルドロジック(Compose の設定、Kotlin のオプション、Hilt など)を再利用可能なプラグインに集約します。

プロジェクト構成

settings.gradle.kts で複合ビルドとして読み込まれる build-logic ディレクトリが、プロジェクトに含まれていることを確認してください。

root/
├── build-logic/
│   ├── convention/
│   │   ├── src/main/kotlin/
│   │   │   └── AndroidApplicationConventionPlugin.kt
│   │   └── build.gradle.kts
│   ├── build.gradle.kts
│   └── settings.gradle.kts
├── gradle/
│   └── libs.versions.toml
├── app/
│   └── build.gradle.kts
└── settings.gradle.kts

ステップ 1:settings.gradle.kts を設定する

プラグイン管理のソースとして build-logic を追加します。

// settings.gradle.kts
pluginManagement {
    includeBuild("build-logic")
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}

ステップ 2:libs.versions.toml で依存関係を定義する

ライブラリとプラグインの両方にバージョンカタログを使用します。

[versions]
androidGradlePlugin = "8.2.0"
kotlin = "1.9.20"

[libraries]
# ...

[plugins]
android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }
android-library = { id = "com.android.library", version.ref = "androidGradlePlugin" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
# Define your own plugins here
nowinandroid-android-application = { id = "nowinandroid.android.application", version = "unspecified" }

ステップ 3:規約プラグインを作成する

build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt 内に作成します。

import com.android.build.api.dsl.ApplicationExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure

class AndroidApplicationConventionPlugin : Plugin<Project> {
    override fun apply(target: Project) {
        with(target) {
            with(pluginManager) {
                apply("com.android.application")
                apply("org.jetbrains.kotlin.android")
            }

            extensions.configure<ApplicationExtension> {
                defaultConfig.targetSdk = 34
                // Configure common options here
            }
        }
    }
}

build-logic/convention/build.gradle.kts で登録するのも忘れないでください。

gradlePlugin {
    plugins {
        register("androidApplication") {
            id = "nowinandroid.android.application"
            implementationClass = "AndroidApplicationConventionPlugin"
        }
    }
}

使用方法

各モジュール(例:app/build.gradle.kts)で、カスタムプラグインを適用します。

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

これにより、モジュールレベルのビルドファイルを大幅にすっきりさせられます。

コメント