A Abhishek
05/02/2024, 9:41 AMconfig.gradle
ext.applyBuildConfigs = { baseExtension -> .... }
baseExtension is the android extension.
I am using it in build.gradle.kts like :
android {
val applyBuildConfigs: Closure<Any?> by extra
applyBuildConfigs(android)
}
This works as expected
I wanted to convert config.gradle to kts , i tried this approach :
config.gradle.kts
val applyConfigs: (com.android.build.gradle.internal.dsl.BaseAppModuleExtension) -> Unit by extra({ baseExtension ->
....
})
but I get the error :
Unresolved reference: android
I can get rid of this error by adding Android Gradle Plugin to the classpath of config.gradle.kts
config.gradle.kts
buildscript {
repositories {
mavenCentral()
google()
}
dependencies {
classpath (libs.agp)
}
}
val applyConfigs: (com.android.build.gradle.internal.dsl.BaseAppModuleExtension) -> Unit by extra({ baseExtension ->
})
I am not sure if this is the correct way but it makes the error go away (IDE still shows error but IDE shown error for all non build.gradle.kts files)
But now when I call applyConfigs(android)
I get the error
class com.android.build.gradle.internal.dsl.BaseAppModuleExtension_Decorated cannot be cast to class com.android.build.gradle.internal.dsl.BaseAppModuleExtension
What would be the correct way to achieve this ? I do not want to create custom plugins for this right now .Thomas Broyer
05/02/2024, 10:00 AMapply(from = "config.gradle")
; then migrate it to a precompiled script plugin in buildSrc
or an included build, and possibly rework your plugin management (add AGP as a dependency to buildSrc
) to avoid those classloader issues.