From 781d185fcf645adc0c5d09e379849471312b31cf Mon Sep 17 00:00:00 2001 From: "Ernesto N. Carrea" Date: Wed, 19 Aug 2026 00:00:42 +0200 Subject: [PATCH 1/2] feat: migrate to built-in Kotlin for AGP 9+ compatibility AGP 9.0 ships built-in Kotlin support, making the standalone kotlin-android plugin (KGP) unnecessary and causing build failures when applied. This PR migrates the plugin to support both AGP 8 (KGP) and AGP 9+ (built-in Kotlin) conditionally. Changes: - android/build.gradle: KGP applied only when AGP < 9 - android/build.gradle: kotlinOptions replaced with kotlin.compilerOptions - example/android/app/build.gradle: removed kotlin-android plugin - example/android/app/build.gradle: kotlinOptions replaced with kotlin.compilerOptions - example/android/settings.gradle: removed kotlin-android plugin declaration Follows the official Flutter migration guide: https://docs.flutter.dev/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors Fixes #45 --- CHANGELOG.md | 8 ++++++++ android/build.gradle | 19 ++++++++++++++----- example/android/app/build.gradle | 15 +++++++++------ example/android/settings.gradle | 1 - pubspec.yaml | 2 +- 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index add848c..8da845c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +#### 3.3.0 · 8/18/2026 + +- Migrated to Flutter's built-in Kotlin support for AGP 9+ compatibility + - KGP (`kotlin-android`) is now applied conditionally only on AGP < 9 + - `kotlinOptions` replaced with `kotlin { compilerOptions {} }` DSL + - See: https://docs.flutter.dev/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors +- Fixes [#45](https://github.com/Tkko/flutter_smart_auth/issues/45) + #### 3.2.0 · 1/1/2025 - Fixed method type diff --git a/android/build.gradle b/android/build.gradle index c39cd9c..f801e11 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -22,7 +22,13 @@ rootProject.allprojects { } apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' + +// AGP 9+ ships built-in Kotlin support; only apply KGP on older AGP. +// See: https://docs.flutter.dev/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors +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. @@ -37,10 +43,6 @@ android { targetCompatibility JavaVersion.VERSION_11 } - kotlinOptions { - jvmTarget = '11' - } - sourceSets { main.java.srcDirs += 'src/main/kotlin' } @@ -50,6 +52,13 @@ android { } } +// AGP 9+ built-in Kotlin: kotlinOptions migrated to kotlin.compilerOptions +kotlin { + compilerOptions { + jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11 + } +} + dependencies { implementation "androidx.core:core-ktx:1.15.0" implementation("androidx.concurrent:concurrent-futures-ktx:1.2.0") diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 545105d..d6a779c 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -1,7 +1,7 @@ plugins { id "com.android.application" - id "kotlin-android" - // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. + // AGP 9+ has built-in Kotlin support; kotlin-android plugin removed + // The Flutter Gradle Plugin must be applied after the Android Gradle plugin. id "dev.flutter.flutter-gradle-plugin" } @@ -15,10 +15,6 @@ android { targetCompatibility JavaVersion.VERSION_11 } - kotlinOptions { - jvmTarget = '11' - } - defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId = "fman.ge.smart_auth_example" @@ -39,6 +35,13 @@ android { } } +// AGP 9+ built-in Kotlin: kotlinOptions migrated to kotlin.compilerOptions +kotlin { + compilerOptions { + jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11 + } +} + flutter { source = "../.." } diff --git a/example/android/settings.gradle b/example/android/settings.gradle index 241cb48..f870177 100644 --- a/example/android/settings.gradle +++ b/example/android/settings.gradle @@ -19,7 +19,6 @@ pluginManagement { plugins { id "dev.flutter.flutter-plugin-loader" version "1.0.0" id "com.android.application" version "8.3.2" apply false - id "org.jetbrains.kotlin.android" version "1.8.0" apply false } include ":app" diff --git a/pubspec.yaml b/pubspec.yaml index 7103ccf..38ed211 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: smart_auth description: Wrapper of Android SMS User Consent API, SMS Retriever API to read one time sms code, get user phone number, OTP, OTC, sms autofill, android autofill homepage: https://github.com/Tkko/flutter_smart_auth repository: https://github.com/Tkko/flutter_smart_auth -version: 3.2.0 +version: 3.3.0 topics: - otp - sms-autofill From a4aa7ab9fbfad29b1aa0c1a796ac2df065bf2fc9 Mon Sep 17 00:00:00 2001 From: "Ernesto N. Carrea" Date: Sun, 27 Sep 2026 15:35:03 +0200 Subject: [PATCH 2/2] fix: complete built-in Kotlin migration for AGP 9 - Honor android.builtInKotlin=false opt-out, not just AGP major version (Flutter's migrator writes that flag by default) - Move kotlinOptions inside the KGP guard: the DSL doesn't exist under built-in Kotlin, and jvmTarget already follows compileOptions there - Register src/main/kotlin via the kotlin source set: built-in Kotlin doesn't compile .kt files added to the java source set Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- android/build.gradle | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index f801e11..ca33917 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -23,10 +23,12 @@ rootProject.allprojects { apply plugin: 'com.android.library' -// AGP 9+ ships built-in Kotlin support; only apply KGP on older AGP. +// AGP 9+ ships built-in Kotlin support; only apply KGP when built-in Kotlin is +// not in effect (older AGP, or projects opting out via android.builtInKotlin=false). // See: https://docs.flutter.dev/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors def agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0] as int -if (agpMajor < 9) { +def builtInKotlin = agpMajor >= 9 && project.findProperty('android.builtInKotlin') != 'false' +if (!builtInKotlin) { apply plugin: 'kotlin-android' } @@ -43,8 +45,18 @@ android { targetCompatibility JavaVersion.VERSION_11 } + // android.kotlinOptions only exists when KGP is applied; with AGP 9 built-in + // Kotlin, jvmTarget follows compileOptions.targetCompatibility. + if (!builtInKotlin) { + kotlinOptions { + jvmTarget = JavaVersion.VERSION_11.toString() + } + } + sourceSets { - main.java.srcDirs += 'src/main/kotlin' + // Kotlin sources must go to the kotlin source set; AGP 9 built-in Kotlin + // does not compile Kotlin files added to the java source set. + main.kotlin.directories.add('src/main/kotlin') } defaultConfig { @@ -52,13 +64,6 @@ android { } } -// AGP 9+ built-in Kotlin: kotlinOptions migrated to kotlin.compilerOptions -kotlin { - compilerOptions { - jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11 - } -} - dependencies { implementation "androidx.core:core-ktx:1.15.0" implementation("androidx.concurrent:concurrent-futures-ktx:1.2.0")