Skip to content

Instantly share code, notes, and snippets.

@yenerm
Created November 21, 2021 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yenerm/f86ff0c9f7b289e1363d8935c6884bda to your computer and use it in GitHub Desktop.
Save yenerm/f86ff0c9f7b289e1363d8935c6884bda to your computer and use it in GitHub Desktop.
CustomPlugin.kt
import com.android.build.api.variant.ApplicationAndroidComponentsExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
class CustomPlugin: Plugin<Project> {
override fun apply(project: Project) {
project.tasks.register("hello"){ task->
task.doLast {
println("Hello " + project.parent?.name)
}
}
val extension = project.extensions.getByName("androidComponents") as ApplicationAndroidComponentsExtension
extension.beforeVariants { variantBuilder ->
if (variantBuilder.name == "staging") {
variantBuilder.enableUnitTest = false
variantBuilder.minSdk = 23
}
}
extension.finalizeDsl { ext->
ext.buildTypes.create("staging").let { buildType ->
buildType.initWith(ext.buildTypes.getByName("debug"))
buildType.manifestPlaceholders["hostName"] = "internal.example.com"
buildType.applicationIdSuffix = ".debugStaging"
//added later while explaining beforeVariants
buildType.isDebuggable = true
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment