Skip to content

Kt-Kraft/build-logic

Repository files navigation

Build Logic for Android

LICENSE GitHub Stars All Contributors

Streamline your Android project configurations with reusable build logic setups. Designed for multi-module projects, this setup reduces boilerplate, standardizes configurations, and simplifies publishing with Gradle.



🚀 Overview

This repository provides a centralized setup for Android build configurations. The conventions include:

  • Standardized build configurations across Android libraries, apps, and Compose modules.
  • Automatic subproject plugin application based on project type (e.g., app, library).
  • Streamlined publishing settings with GitHub Packages.

📝 Setup & Usage

To integrate this build logic into your Android project, follow the steps below.

Step 1: Configure settings.gradle.kts

Add the custom plugin repository to your root project settings.gradle.kts:

pluginManagement {
  repositories {
    maven(url = "https://maven.pkg.github.com/Kt-Kraft/build-logic/") {
      name = "GitHubPackages"
      credentials {
        username = providers.gradleProperty("github.username").orNull
          ?: System.getenv("GITHUB_USERNAME")
        password = providers.gradleProperty("github.token").orNull
          ?: System.getenv("GITHUB_TOKEN")
      }
    }
    google()
    mavenCentral()
    gradlePluginPortal()
  }
}

Step 2: Update build.gradle.kts in Root Project

Add plugin aliases and configurations in your root project’s build.gradle.kts:

plugins {
  alias(libs.plugins.convention.android.app) apply false
  alias(libs.plugins.convention.android.lib) apply false
  alias(libs.plugins.convention.compose.app) apply false
  alias(libs.plugins.convention.compose.lib) apply false
  alias(libs.plugins.convention.publishing) apply false
  alias(libs.plugins.convention.android.config)
  alias(libs.plugins.convention.publish.config)
}

// Initial configuration for subprojects
convention {
  android {
    minSdk.set(26)
    targetSdk.set(34)
    compileSdk.set(34)
  }

  publishing {
    pom {
      setGitHubProject {
        owner = "indramahkota"
        repository = "easy-android"
      }

      licenses { mit() }

      developers {
        developer(
          id = "indramahkota",
          name = "Indra Mahkota",
          email = "indramahkota1@gmail.com",
        )
      }
    }
  }
}

Step 3: Apply Plugins in Submodules

In your submodule build.gradle.kts files, apply the necessary plugins:

plugins {
  alias(libs.plugins.convention.compose.app)
  alias(libs.plugins.secret.gradle.plugin)
}

// or

plugins {
  alias(libs.plugins.convention.android.lib)
  alias(libs.plugins.convention.publishing)
}