android-gradle-logic

โดย livekit

คำแนะนำจากผู้เชี่ยวชาญเกี่ยวกับการตั้งค่าตรรกะการสร้าง Gradle ที่ปรับขนาดได้โดยใช้ Convention Plugins และ Version Catalogs

npx skills add https://github.com/livekit/client-sdk-android --skill android-gradle-logic

Android Gradle Build Logic & Convention Plugins

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.

Goal

Stop copy-pasting code between build.gradle.kts files. Centralize build logic (Compose setup, Kotlin options, Hilt, etc.) in reusable plugins.

Project Structure

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

Step 1: Configure settings.gradle.kts

Include 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()
    }
}

Step 2: Define Dependencies in libs.versions.toml

Use 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" }

Step 3: Create a Convention Plugin

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"
        }
    }
}

Usage

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.

Skills เพิ่มเติมจาก livekit

android-coroutines
livekit
นำไปใช้และตรวจสอบ Kotlin Coroutines บน Android: กำหนดค่า CoroutineScopes, จัดการ Dispatchers, เปิดเผย StateFlow/SharedFlow จาก ViewModels, รวบรวมด้วย…
official
livekit-agents
livekit
สร้างเอเจนต์เสียง AI บน LiveKit Cloud ด้วยเวิร์กโฟลว์ที่มีโครงสร้าง เวลาแฝงต่ำ และการครอบคลุมการทดสอบที่จำเป็น ใช้ LiveKit Cloud และ LiveKit Inference สำหรับโครงสร้างพื้นฐานที่จัดการและโมเดล AI โดยไม่ต้องใช้คีย์ API แยกต่างหาก ออกแบบเอเจนต์รอบการส่งต่อ (การเปลี่ยนผ่านระหว่างเอเจนต์) และงาน (การดำเนินการที่มีขอบเขต) เพื่อแยกบริบทและลดเวลาแฝง การใช้งานเอเจนต์ทุกครั้งต้องมีการทดสอบที่ครอบคลุมการสนทนาพื้นฐาน การเรียกใช้เครื่องมือ การจัดการข้อผิดพลาด และกรณีขอบก่อนการปรับใช้ เสมอ...
official
livekit-simulations
livekit
สร้างสถานการณ์ทดสอบที่ตรงเป้าหมายสำหรับเอเจนต์เสียงหรือแชทของ LiveKit และรันเป็นซิมูเลชัน — ในเครื่อง จากโค้ดของเอเจนต์เองรวมกับสิ่งที่ผู้ใช้ต้องการ…
official
gradle-build-performance
livekit
ดีบักและปรับปรุงประสิทธิภาพการสร้าง Android/Gradle ใช้เมื่อการสร้างช้า กำลังตรวจสอบประสิทธิภาพ CI/CD วิเคราะห์ build scans หรือระบุ…
official