I am creating a gradle plugin for android projects in which I intended to find the android plugin to get the namespace of the project. In the plugin’s gradle build file I am using implementation("com.android.tools.build:gradle:8.1.4")
to get the CommonExtension of the android.
and I have create a typealias for the common extension.
import com.android.build.api.dsl.CommonExtension
typealias AndroidExtension = CommonExtension<*, *, *, *,*>
And In the task I am getting the android extension using the line
@Internal
val androidExtension = project.extensions.getByName<AndroidExtension>("android")
When applying my plugin to an android project having same implementation of android tools.build.gradle:8.1.4, It works fine but when I update the plugin’s implementation of android.tools.build.gradle to 8.5.*, in the same project which the plugin was applied earlier throw exception
> Mismatch of count of formal and actual type arguments in constructor of com.android.build.api.dsl.CommonExtension: 5 formal argument(s) 6 actual argument(s)
So, to use my plugin, an android project needs to update com.android.application plugin to 8.5.* which I believe is not ideal for the plugin. My question is, how do I support different Android projects?
I am considering creating a compatibility map for my plugin, such as:
For com.android.application
:
- 8.1.4 – my plugin version 1.0
- 8.5.2 – my plugin version 2.0
How do I achieve this? I guess this is possible after I publish my plugin.