Slackbot
09/04/2023, 2:10 PMFabio Berta
09/04/2023, 2:10 PMVampire
09/04/2023, 2:14 PMFabio Berta
09/04/2023, 2:15 PMVampire
09/04/2023, 2:16 PMFabio Berta
09/04/2023, 2:18 PMFabio Berta
09/04/2023, 2:18 PMFabio Berta
09/04/2023, 2:28 PMimport com.github.fnberta.kotlinbuild.configureAndroid
plugins {
kotlin("android")
id("com.android.application")
}
android {
configureAndroid(this)
... more config
}
plugin 2:
import com.github.fnberta.kotlinbuild.configureAndroid
plugins {
kotlin("android")
id("com.android.library")
}
android {
configureAndroid(this)
... more config
}
The shared function:
import com.android.build.api.dsl.CommonExtension
import org.gradle.api.Project
internal fun Project.configureAndroid(commonExtension: CommonExtension<*, *, *, *, *>) {
commonExtension.apply {
... apply config
}
}
}Fabio Berta
09/04/2023, 2:29 PMFabio Berta
09/04/2023, 2:39 PMcom.android.application or com.android.library to get access to the android extensionVampire
09/04/2023, 2:43 PMval TARGET_SDK = 34
val MIN_SDK = 26
fun Project.configureAndroidCommon() = configure<CommonExtension<*, *, *, *, *>> {
compileSdk = TARGET_SDK
defaultConfig {
minSdk = MIN_SDK
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
}
pluginManager.withPlugin("com.android.application") {
configureAndroidCommon()
}
pluginManager.withPlugin("com.android.library") {
configureAndroidCommon()
}
but you probably don't win too much by that.
As the extension function is only used within your conventionp plugin project, it is probably find and I misunderstood.
But then the answer is "no", a working project does not really help to see the error in the non-working project. 😄Fabio Berta
09/04/2023, 2:47 PMVampire
09/04/2023, 2:48 PMFabio Berta
09/04/2023, 2:48 PMpluginManager.withPlugin didn't know about that, thanks! But I somehow feel this is less explicit than having specific application and library plugins?Fabio Berta
09/04/2023, 2:49 PMVampire
09/04/2023, 2:49 PMpluginManager.withPlugin is the way to react to a plugin being appliedVampire
09/04/2023, 2:49 PMFabio Berta
09/04/2023, 2:51 PMFabio Berta
09/04/2023, 2:52 PMconfigureAndroidCommon sets
defaultConfig {
minSdk = MIN_SDK
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Now in consumers applying this plugin I'd like to extend this and specify for example:
defaultConfig {
someOtherProperty = something
}
Is this possible? Are they getting merged?Fabio Berta
09/04/2023, 2:52 PMVampire
09/04/2023, 2:53 PMthis in android { configureAndroid(this) } and press Ctrl+Shift+p?Vampire
09/04/2023, 2:54 PMOr does the second override the firstUnless the AGP is doing more weird stuff than I know, it should behave as expected, being additive.
Vampire
09/04/2023, 2:54 PMFabio Berta
09/04/2023, 2:55 PMFabio Berta
09/04/2023, 2:55 PMCh_srf_android_android_application_gradleVampire
09/04/2023, 2:56 PMthis is not the CommonExtension in that case, but the script classVampire
09/04/2023, 2:56 PMVampire
09/04/2023, 2:59 PM--scan of the working and non-working cases?Fabio Berta
09/04/2023, 3:00 PMconfigureAndroid(this) , I can build, then I uncomment it and do the ctrl shift p thing and it shows the correct type 🤷Fabio Berta
09/04/2023, 3:04 PMFabio Berta
09/04/2023, 3:04 PMFabio Berta
09/04/2023, 3:07 PMFabio Berta
09/04/2023, 3:07 PMVampire
09/04/2023, 3:08 PMFabio Berta
09/04/2023, 3:14 PMFabio Berta
09/04/2023, 3:14 PMVampire
09/04/2023, 3:18 PMFabio Berta
09/04/2023, 3:23 PMFabio Berta
09/04/2023, 3:23 PMFabio Berta
09/04/2023, 3:23 PMWARNING: Unsupported Kotlin plugin version.
The `embedded-kotlin` and `kotlin-dsl` plugins rely on features of Kotlin `1.8.10` that might work differently than in the requested version `1.9.0`.Fabio Berta
09/04/2023, 3:24 PMFabio Berta
09/04/2023, 3:26 PMalias(libs.plugins.android.library) apply false but this should only specify a version and not apply it?Vampire
09/04/2023, 3:26 PMFabio Berta
09/04/2023, 3:27 PMVampire
09/04/2023, 3:27 PMapply falseFabio Berta
09/04/2023, 3:31 PMVampire
09/04/2023, 3:31 PMFabio Berta
09/04/2023, 3:33 PMFabio Berta
09/04/2023, 3:33 PMVampire
09/04/2023, 3:40 PMkotlin:1.8.10-gradle76 and kotlin-scripting:1.8.10-gradle76 are applied while in the non-working both are applied with 1.9.0-gradle80.Fabio Berta
09/04/2023, 3:42 PMFabio Berta
09/04/2023, 3:44 PMbuild.gradle.kts specifies
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.kotlin.android) apply falseFabio Berta
09/04/2023, 3:45 PMError resolving plugin [id: 'org.jetbrains.kotlin.jvm', version: '1.9.0']
> The request for this plugin could not be satisfied because the plugin is already on the classpath with an unknown version, so compatibility cannot be checked.Fabio Berta
09/04/2023, 3:46 PMbuild.gradle.kts specifies for this one specific project that has the convention pluginsFabio Berta
09/04/2023, 3:46 PMVampire
09/04/2023, 3:47 PMFabio Berta
09/04/2023, 3:47 PMFabio Berta
09/04/2023, 3:48 PM