Cross-posting from the gradle community slack (<ht...
# android
t
Cross-posting from the gradle community slack (https://gradle-community.slack.com/archives/CA7UM03V3/p1609220513181600) I'm trying to understand the root cause of this error message:
Copy code
* What went wrong:
An exception occurred applying plugin request [id: 'org.jetbrains.kotlin.android', version: '1.4.21']
> Failed to apply plugin 'org.jetbrains.kotlin.android'.
   > Extension with name 'android' does not exist. Currently registered extension names: [ext, kotlin, kotlinTestRegistry]
which is a result of the following setup:
Copy code
// root build.gradle
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.2.0-alpha15"
    }
}
// app/build.gradle
plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android' version '1.4.21'
}
and then executing
./gradlew help
. Build scan: https://scans.gradle.com/s/t7w3bwv3pingm/build-dependencies?toggled=W1swXSxbMV0sWzEsMF0sWzAsMF0sWzAsMV1d I recognize, btw, that this is a non-standard setup. To reiterate, my goal is to understand what that error means and why it happens.
relatedly, the kotlin-android plugin should be able to be applied this way, per docs on the gradle plugin portal https://plugins.gradle.org/plugin/org.jetbrains.kotlin.android
so I guess the question is, why can't the kotlin-android plugin "see" the
android
extension in the example above? It looks like, if KGP and AGP are loaded on the same classpath in the same script context, then there's no problem, but if KGP is in a child, then it barfs, and I don't understand why. If there's some ordering problem, I also don't understand that, since I apply AGP before I apply KGP, so
android
should exist, right?
j
i read this error as it’s missing the android extension dsl. what happens if you add this
Copy code
android {}
below the plugins block? i’d expect the error to go away or change slightly.
t
I ended up filing an issue against gradle for this https://github.com/gradle/gradle/issues/15664 tl;dr it looks like an ordering issue. In the failure case, KGP is applied first, before the android extension has been created by AGP. KGP does not use withPlugin or anything like that; it just assumes it is applied after AGP