Created
April 22, 2018 13:20
-
-
Save tomkoptel/aca32b46defb6856c2d3b389740e6959 to your computer and use it in GitHub Desktop.
A shortcut API to list Android Gradle variants.
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
/** | |
* Returns the collection of Android variants on the basis of applied plugin. If the Android plugins are missing we | |
* are throwing build error. | |
*/ | |
internal fun Project.getAndroidVariantsOrThrow(errorMessage: String): DomainObjectCollection<out BaseVariant> { | |
return when { | |
this.plugins.hasPlugin("com.android.application") -> { | |
val ext = project.extensions.findByType(AppExtension::class.java) | |
ext!!.applicationVariants | |
} | |
this.plugins.hasPlugin("com.android.test") -> { | |
val ext = project.extensions.findByType(TestExtension::class.java) | |
ext!!.applicationVariants | |
} | |
this.plugins.hasPlugin("com.android.library") -> { | |
val ext = project.extensions.findByType(LibraryExtension::class.java) | |
ext!!.libraryVariants | |
} | |
else -> throw IllegalArgumentException(errorMessage) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment