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
| package extensions | |
| import com.android.build.gradle.AppExtension | |
| import com.android.build.gradle.BaseExtension | |
| import com.android.build.gradle.FeatureExtension | |
| import com.android.build.gradle.LibraryExtension | |
| import com.android.build.gradle.api.BaseVariant | |
| import org.gradle.api.DomainObjectSet | |
| import org.gradle.api.GradleException | |
| import org.gradle.api.Project |
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
| <?xml version="1.0" encoding="utf-8"?> | |
| <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:app="http://schemas.android.com/apk/res-auto" | |
| xmlns:tools="http://schemas.android.com/tools" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| tools:context=".MainActivity"> | |
| <View | |
| android:id="@+id/color_1_view" |
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
| <color name="color1"/> | |
| <color name="color2"/> | |
| <color name="color3"/> |
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
| apply plugin: 'MyFirstPlugin' |
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
| gradlePlugin { | |
| plugins { | |
| create("MyFirstPlugin") { | |
| id = "MyFirstPlugin" | |
| implementationClass = "MyFirstPlugin" | |
| } | |
| } | |
| } |
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
| 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 myTask = "myFirstTask${variant.name.capitalize()}" | |
| // Register a simple task as a lambda. We can later move this to its own | |
| // class to make our code cleaner and also add some niceties. |
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
| fun Project.android(): BaseExtension { | |
| val android = project.extensions.findByType(BaseExtension::class.java) | |
| if (android != null) { | |
| return android | |
| } else { | |
| throw GradleException("Project $name is not an Android project") | |
| } | |
| } | |
| fun BaseExtension.variants(): DomainObjectSet<out BaseVariant> { |
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
| class MyFirstPlugin : Plugin<Project> { | |
| override fun apply(project: Project) { | |
| // Magic goes here | |
| } | |
| } |
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
| apply plugin: 'java-gradle-plugin' // Allows us to create and configure custom plugins | |
| apply plugin: 'kotlin' //Needed as we'll write our plugin in Kotlin | |
| buildscript { | |
| ext.kotlin_version = '1.3.71' | |
| ext.gradle_version = '3.5.3' | |
| repositories { | |
| google() | |
| jcenter() | |
| } |
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
| rootProject.name='PluginSample' | |
| include ':app', 'buildSrc' |