Last active
June 2, 2020 17:01
-
-
Save PaoloMilano/c7dd9ca6dce710df32c56d7ba58320ec 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 extensions.android | |
import extensions.variants | |
import org.gradle.api.Plugin | |
import org.gradle.api.Project | |
import java.io.File | |
internal class MyFirstPlugin : Plugin<Project> { | |
override fun apply(project: Project) { | |
project.android().variants().all { variant -> | |
// Make a task for each combination of build type and product flavor | |
val colorTaskName = "generateColors${variant.name.capitalize()}" | |
val outputPath = "${project.buildDir}/generated/res" | |
// Register the task. Gradle will parse and add the tasks for us for the given names. | |
project.tasks.register(colorTaskName, ColorsTask::class.java) { colorTask -> | |
colorTask.group = "MyPluginTasks" | |
// We write our output in the build folder. Also note that we keep a | |
// reference to this so as to later mark it as a generated resource folder | |
val outputDirectory = | |
File("$outputPath/${variant.dirName}").apply { mkdir() } | |
colorTask.outputFile = File(outputDirectory, "values/generated_colors.xml") | |
// Marks the output directory as an app resource folder | |
variant.registerGeneratedResFolders( | |
project.files(outputDirectory).builtBy( | |
colorTask | |
) | |
) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment