android-gradle-logic by new-silvermoon/awesome-android-agent-skills
npx skills add https://github.com/new-silvermoon/awesome-android-agent-skills --skill android-gradle-logic此技能帮助您使用 Gradle 约定插件 和 版本目录,遵循 "Now in Android" (NiA) 架构,为 Android 应用配置一个可扩展、可维护的构建系统。
停止在 build.gradle.kts 文件之间复制粘贴代码。将构建逻辑(Compose 设置、Kotlin 选项、Hilt 等)集中到可重用的插件中。
确保您的项目有一个 build-logic 目录,并在 settings.gradle.kts 中将其包含为复合构建。
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
settings.gradle.kts将 build-logic 包含为插件管理源。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
// settings.gradle.kts
pluginManagement {
includeBuild("build-logic")
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
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" }
# 在此处定义您自己的插件
nowinandroid-android-application = { id = "nowinandroid.android.application", version = "unspecified" }
在 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
// 在此处配置通用选项
}
}
}
}
别忘了在 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)
}
这将极大地清理模块级别的构建文件。
每周安装量
210
代码仓库
GitHub 星标数
565
首次出现
2026 年 1 月 27 日
安全审计
安装于
opencode191
codex189
gemini-cli159
claude-code151
github-copilot150
kimi-cli141
This skill helps you configure a scalable, maintainable build system for Android apps using Gradle Convention Plugins and Version Catalogs , following the "Now in Android" (NiA) architecture.
Stop copy-pasting code between build.gradle.kts files. Centralize build logic (Compose setup, Kotlin options, Hilt, etc.) in reusable plugins.
Ensure your project has a build-logic directory included in settings.gradle.kts as a composite build.
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
settings.gradle.ktsInclude the build-logic as a plugin management source.
// settings.gradle.kts
pluginManagement {
includeBuild("build-logic")
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
libs.versions.tomlUse the Version Catalog for both libraries and plugins.
[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" }
Inside 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
}
}
}
}
Don't forget to register it in build-logic/convention/build.gradle.kts:
gradlePlugin {
plugins {
register("androidApplication") {
id = "nowinandroid.android.application"
implementationClass = "AndroidApplicationConventionPlugin"
}
}
}
Apply your custom plugin in your modules (e.g., app/build.gradle.kts):
plugins {
alias(libs.plugins.nowinandroid.android.application)
}
This drastically cleans up module-level build files.
Weekly Installs
210
Repository
GitHub Stars
565
First Seen
Jan 27, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode191
codex189
gemini-cli159
claude-code151
github-copilot150
kimi-cli141
Kotlin Exposed ORM 模式指南:DSL查询、DAO、事务管理与生产配置
913 周安装
Django安全最佳实践指南 - 防范常见漏洞,配置生产环境安全设置
2,100 周安装
Nano Banana Pro 提示词推荐:10000+ AI 图像生成提示词库,支持 Midjourney、DALL-E 3、Stable Diffusion
2,100 周安装
Python Office自动化脚本:Word/Excel批量处理、模板填充、数据合并与分析
2,100 周安装
微信小程序开发指南 - 腾讯云CloudBase集成、调试发布与项目结构最佳实践
2,200 周安装
Payload CMS 开发指南:TypeScript 原生 CMS 与 Next.js 集成教程
2,100 周安装
OpenTUI 终端用户界面开发框架 - 构建高性能终端应用指南
2,200 周安装