diff --git a/workmanager_android/android/build.gradle b/workmanager_android/android/build.gradle index 3552b1be..4ce77b98 100644 --- a/workmanager_android/android/build.gradle +++ b/workmanager_android/android/build.gradle @@ -9,7 +9,11 @@ rootProject.allprojects { } apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' +// AGP 9+ has built-in Kotlin support; older versions need the plugin explicitly. +def agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0] as int +if (agpMajor < 9) { + apply plugin: 'kotlin-android' +} android { // Conditional for compatibility with AGP <4.2. @@ -34,12 +38,13 @@ android { targetCompatibility JavaVersion.VERSION_1_8 } - kotlinOptions { - tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { - kotlinOptions.jvmTarget = "1.8" + if (agpMajor < 9) { + kotlinOptions { + tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { + kotlinOptions.jvmTarget = "1.8" + } } } - } dependencies {