Last active
August 7, 2025 12:28
-
-
Save Pratham-Sortly/f366c4bf6e86c7dc7e35ad961815eb3e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.android.build.api.dsl.LibraryExtension | |
| import extension.getLibsFromVersionCatalog | |
| import org.gradle.api.JavaVersion | |
| import org.gradle.api.Plugin | |
| import org.gradle.api.Project | |
| import org.gradle.api.artifacts.VersionCatalog | |
| import org.gradle.kotlin.dsl.configure | |
| class ModuleLevelPlugin : Plugin<Project> { | |
| override fun apply(project: Project): Unit = with(project) { | |
| val libs = getLibsFromVersionCatalog() | |
| configurePlugins(libs) | |
| extensions.configure<LibraryExtension> { | |
| addSdkAndConfigs(libs) | |
| addBuildTypes() | |
| addCompileOptions() | |
| addBuildFeatures() | |
| } | |
| } | |
| private fun Project.configurePlugins(libs: VersionCatalog) { | |
| plugins.apply(libs.findPlugin("android-library").get().get().pluginId) | |
| plugins.apply(libs.findPlugin("kotlin-android").get().get().pluginId) | |
| plugins.apply(libs.findPlugin("kotlin-compose").get().get().pluginId) | |
| } | |
| private fun LibraryExtension.addSdkAndConfigs(libs: VersionCatalog) { | |
| compileSdk = libs.findVersion("android.compileSdk").get().requiredVersion.toInt() | |
| defaultConfig { | |
| minSdk = libs.findVersion("android.minSdk").get().requiredVersion.toInt() | |
| testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | |
| consumerProguardFiles("consumer-rules.pro") | |
| } | |
| } | |
| private fun LibraryExtension.addBuildTypes() { | |
| buildTypes { | |
| getByName("debug") { | |
| isShrinkResources = false | |
| isMinifyEnabled = false | |
| buildConfigField("boolean", "ENABLE_ANALYTICS", "false") | |
| } | |
| create("qa") { | |
| initWith(buildTypes.getByName("debug")) | |
| isShrinkResources = false | |
| isMinifyEnabled = false | |
| buildConfigField("boolean", "ENABLE_ANALYTICS", "true") | |
| } | |
| getByName("release") { | |
| isMinifyEnabled = false | |
| buildConfigField("boolean", "ENABLE_ANALYTICS", "true") | |
| proguardFiles( | |
| getDefaultProguardFile("proguard-android-optimize.txt"), | |
| "proguard-rules.pro" | |
| ) | |
| } | |
| } | |
| } | |
| private fun LibraryExtension.addCompileOptions() { | |
| compileOptions { | |
| sourceCompatibility = JavaVersion.VERSION_11 | |
| targetCompatibility = JavaVersion.VERSION_11 | |
| } | |
| } | |
| private fun LibraryExtension.addBuildFeatures() { | |
| buildFeatures { | |
| buildConfig = true | |
| compose = true | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment