ursus
07/18/2021, 2:38 AMandroidComponets {
onVariants {
println "variant=$it"
}
}
why does this not compile? its eaxcly the official sample
ephemient
07/18/2021, 3:40 AMonVariants
is AGP 7.0+ursus
07/18/2021, 7:50 AMVampire
07/18/2021, 9:14 AMn
in componentsursus
07/18/2021, 11:17 AMursus
07/18/2021, 11:50 AMandroidComponents {
onVariants { variant ->
println "variant=$variant"
}
}
* Where:
Build file 'C:\Misc\mo2-android\tesco-mobile\app\build.gradle' line: 162
* What went wrong:
A problem occurred evaluating project ':tesco-mobile:app'.
> No signature of method: build_7qrc4nz4nypxqatfu7rooj9dy.androidComponents() is applicable for argument types: (build_7qrc4nz4nypxqatfu7rooj9dy$_run_closure2) values: [build_7qrc4nz4nypxqatfu7rooj9dy$_run_closure2@3d15c5c7]
the 162 is the androidComponents line
https://developer.android.com/reference/tools/gradle-api/7.0/com/android/build/api/extension/AndroidComponentsExtension#onvariants
AGP 7.0.0-beta05
Should work, right?ursus
07/18/2021, 11:55 AMandroidComponents {
onVariants(selector().all()) { variant ->
println "variant=$variant"
}
}
but why? the function has it as a default param, so I should be able to call it paramless on my end? is this a groovy thing?ursus
07/18/2021, 11:59 AMgradlew help
so I guess its just syntactic sugar 😕Vampire
07/18/2021, 12:18 PMNormally, if you write a Kotlin function with default parameter values, it will be visible in Java only as a full signature, with all parameters present. If you wish to expose multiple overloads to Java callers, you can use the @JvmOverloads annotation.
So when calling a Kotlin function with default parameters, you have to provide all arguments. If the developers would be nice and honor that a usage from Groovy is likely for a Gradle plugin, they could add that annotation so that the overloads are generated.
ursus
07/18/2021, 12:27 PMursus
07/18/2021, 12:38 PM