diff --git a/android/build.gradle b/android/build.gradle index a2a023fd..802aeb22 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -22,7 +22,14 @@ allprojects { } apply plugin: "com.android.library" -apply plugin: "kotlin-android" + +// AGP 9 ships Kotlin support built in and fails the build if the Kotlin +// Gradle Plugin is applied on top of it. Keep applying it for AGP 8 so this +// module still builds on older toolchains. +def agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0] as int +if (agpMajor < 9) { + apply plugin: "kotlin-android" +} android { namespace = "io.github.zeshuaro.google_api_headers" @@ -34,10 +41,6 @@ android { targetCompatibility = JavaVersion.VERSION_11 } - kotlinOptions { - jvmTarget = JavaVersion.VERSION_11 - } - sourceSets { main.java.srcDirs += "src/main/kotlin" test.java.srcDirs += "src/test/kotlin" @@ -64,3 +67,10 @@ android { } } } + +// Replaces the removed `android.kotlinOptions`; works under both toolchains. +kotlin { + compilerOptions { + jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11 + } +}