7

how are you doing?

Did you get this kind of error when writing a gradle plugin using kotlin DSL:

Cannot access 'com.android.build.gradle.internal.dsl.Lockable' which is a supertype of 'com.android.build.gradle.BaseExtension'. Check your module classpath for missing or conflicting dependencies

Here is the complete code:

import org.gradle.api.Project
import com.android.build.gradle.BaseExtension
import org.gradle.kotlin.dsl.getByType

private typealias AndroidBaseExtension = BaseExtension

fun Project.configureAndroid() = this.extensions.getByType<AndroidBaseExtension>().run{
    compileSdkVersion(30)
}

Thanks in advance for your HELP.

2 Answers2

1

You need a dependency on the new version

implementation("com.android.tools.build:gradle:7.1.0-alpha12")

in your build.gradle.kts (buildSrc module)

Frost
  • 11
  • 1
  • I also had to add implementation("org.gradle.kotlin:gradle-kotlin-dsl-plugins:2.2.0") to the build.gradle.ks(buildSrc module) and in the plugin section I had to add id ("org.gradle.kotlin.kotlin-dsl") version "2.2.0". You need those because of the GetByType – Tom Rutchik Feb 15 '22 at 20:01
  • And I also eliminate the typealias line and replaced AndroidBaseExtension to just BaseExtension. The typealias might be useful it the code had BaseExtension's from multiple plugins and you need to differentiate between different BaseExtension's, but in the posted code the typealias is not necessary. – Tom Rutchik Feb 15 '22 at 20:17
-1

delete ~/.gradle/caches, Invalidate Caches and Restart Android Studio, problem fixed, at least for me.

mochadwi
  • 1,190
  • 9
  • 32
  • 87
聂超群
  • 1,659
  • 6
  • 14