StefMa
12/13/2017, 7:34 AMtask("Hello") {
println("Hello World")
}
This works.
Now I wanted to map this to my android project.
I’ve updated the script to:
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath("com.android.tools.build:gradle:3.0.1")
}
}
apply {
plugin("com.android.application")
}
android {
compileSdkVersion("26")
}
But if I run it I get:
build.gradle.kts:18:1: Unresolved reference: android
build.gradle.kts:19:3: Unresolved reference: compileSdkVersionWhat I’m doing wrong? I’ve already checked out the samples. With the hello-android I don’t have that issue 😕
Czar
12/13/2017, 8:08 AMandroid {}
, it is not generated. Groovy dsl being dynamic can provide it dynamically, Kotlin can't.
What you should do here is add import:
import com.android.build.gradle.AppExtension
then configure the android app extension: configure<AppExtension> {
compileSdkVersion = "26"
}
if Google was kind enough to provide their plugins in gradle plugins repository you could've used plugins {}
block and gradle-dsl would've been able to generate static android
accessor, but hey, separatism rules and Google wants you to download plugins from their repo.StefMa
12/13/2017, 8:40 AMhello-android
the static android accessor?eskatos
12/13/2017, 8:52 AMplugins {}
block, see here: https://github.com/gradle/kotlin-dsl/blob/develop/samples/hello-android/settings.gradle.ktsStefMa
12/13/2017, 9:00 AMplugin{}
does all the magic stuff 🙂 Thanks guys 👍