From 3f61ec07b9da58d710b512b334baf60181930a5f Mon Sep 17 00:00:00 2001 From: Joonas Kerttula Date: Thu, 4 Jun 2026 14:37:59 +0300 Subject: [PATCH 1/2] chore: git mv gradle files as gradle.kts --- android/{build.gradle => build.gradle.kts} | 0 android/{settings.gradle => settings.gradle.kts} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename android/{build.gradle => build.gradle.kts} (100%) rename android/{settings.gradle => settings.gradle.kts} (100%) diff --git a/android/build.gradle b/android/build.gradle.kts similarity index 100% rename from android/build.gradle rename to android/build.gradle.kts diff --git a/android/settings.gradle b/android/settings.gradle.kts similarity index 100% rename from android/settings.gradle rename to android/settings.gradle.kts From a0e885aa0d5322e82c4dcfc729e4945efb95705a Mon Sep 17 00:00:00 2001 From: Joonas Kerttula Date: Thu, 4 Jun 2026 15:02:07 +0300 Subject: [PATCH 2/2] feat: modernize Android build toolchain MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Convert the plugin's android/build.gradle + settings.gradle to Kotlin DSL (.kts). - Plugin: apply KGP conditionally (only on AGP < 9). - Replace deprecated `kotlinOptions {}` with `kotlin { compilerOptions {} }` in plugin and example. - Raise Java/Kotlin target 11 → 17 (matches Flutter templates and Navigation SDK requirement). - Bump example Gradle wrapper 8.13 → 8.14.3 and Kotlin (KGP) 2.1.0 → 2.3.20. - Gate the ktfmt formatter behind `-Pktfmt` so it is never forced on consuming apps. Co-Authored-By: Claude Opus 4.8 --- android/build.gradle.kts | 116 +++++++++++------- android/settings.gradle.kts | 4 +- example/android/app/build.gradle.kts | 20 +-- .../gradle/wrapper/gradle-wrapper.properties | 2 +- example/android/settings.gradle.kts | 2 +- melos.yaml | 2 +- 6 files changed, 90 insertions(+), 56 deletions(-) diff --git a/android/build.gradle.kts b/android/build.gradle.kts index eed4aa0..06a4c28 100644 --- a/android/build.gradle.kts +++ b/android/build.gradle.kts @@ -1,4 +1,4 @@ -// Copyright 2023 Google LLC +// Copyright 2026 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,24 +12,36 @@ // See the License for the specific language governing permissions and // limitations under the License. -group 'com.google.maps.flutter.driver' -version '1.0-SNAPSHOT' - buildscript { - ext.kotlin_version = '2.1.0' + val kotlinVersion = "2.3.20" repositories { google() mavenCentral() - maven { url "https://plugins.gradle.org/m2/" } + // Only needed to resolve ktfmt below (development/CI-only, gated by -Pktfmt). + if (providers.gradleProperty("ktfmt").isPresent) { + maven { url = uri("https://plugins.gradle.org/m2/") } + } } dependencies { - classpath 'com.android.tools.build:gradle:8.8.1' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath 'com.ncorti.ktfmt.gradle:plugin:0.21.0' + classpath("com.android.tools.build:gradle:8.8.1") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") + // ktfmt (Kotlin formatter) is a development/CI-only tool. Pulling it onto the classpath + // (and applying it below) is gated behind -Pktfmt so it is never forced on apps that + // depend on this plugin. Enabled by `melos run format:android`. + if (providers.gradleProperty("ktfmt").isPresent) { + classpath("com.ncorti.ktfmt.gradle:plugin:0.21.0") + } } } +plugins { + id("com.android.library") +} + +group = "com.google.maps.flutter.driver" +version = "1.0-SNAPSHOT" + allprojects { repositories { google() @@ -37,58 +49,76 @@ allprojects { } } -apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' -apply plugin: 'com.ncorti.ktfmt.gradle' +// Apply the Kotlin Gradle Plugin (KGP) only when consumed by AGP < 9. AGP 9+ ships built-in Kotlin, +// so applying KGP there is unnecessary and triggers a Flutter deprecation warning. Keeping it +// conditional preserves compatibility for apps still on AGP 8. +// https://docs.flutter.dev/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors#supporting-flutter-versions-earlier-than-3-44 +val agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.substringBefore('.').toInt() +if (agpMajor < 9) { + apply(plugin = "org.jetbrains.kotlin.android") +} -ktfmt { - googleStyle() +// ktfmt is applied only for development/CI formatting (-Pktfmt), so it is never forced on apps +// that depend on this plugin. Run via `melos run format:android` (which passes -Pktfmt). +if (providers.gradleProperty("ktfmt").isPresent) { + apply(plugin = "com.ncorti.ktfmt.gradle") + // Configured dynamically (no compile-time type reference) so this script still compiles when + // ktfmt is absent from the classpath, i.e. for apps that depend on this plugin. + extensions.getByName("ktfmt").withGroovyBuilder { "googleStyle"() } } android { - if (project.android.hasProperty("namespace")) { - namespace 'com.google.maps.flutter.driver' - } + namespace = "com.google.maps.flutter.driver" - compileSdk 36 + compileSdk = 36 compileOptions { - sourceCompatibility JavaVersion.VERSION_11 - targetCompatibility JavaVersion.VERSION_11 - } - - kotlinOptions { - jvmTarget = '11' + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } sourceSets { - main.java.srcDirs += 'src/main/kotlin' - test.java.srcDirs += 'src/test/kotlin' + getByName("main") { + java.srcDirs("src/main/kotlin") + } + getByName("test") { + java.srcDirs("src/test/kotlin") + } } defaultConfig { - minSdkVersion 26 - } - - dependencies { - implementation 'com.google.android.libraries.mapsplatform.transportation:transportation-driver:7.0.0' - implementation 'androidx.startup:startup-runtime:1.2.0' - testImplementation 'org.jetbrains.kotlin:kotlin-test' - testImplementation 'io.mockk:mockk:1.13.9' - testImplementation 'junit:junit:4.13.2' - testImplementation 'org.robolectric:robolectric:4.11.1' + minSdk = 26 } testOptions { unitTests { - includeAndroidResources = true - } - unitTests.all { - testLogging { - events "passed", "skipped", "failed", "standardOut", "standardError" - outputs.upToDateWhen {false} - showStandardStreams = true + isIncludeAndroidResources = true + all { + it.testLogging { + events("passed", "skipped", "failed", "standardOut", "standardError") + showStandardStreams = true + } + it.outputs.upToDateWhen { false } } } } } + +// Configure the Kotlin JVM target via the compilerOptions DSL (replaces the deprecated +// android.kotlinOptions block). Configured through the extension so it works whether the Kotlin +// plugin is applied conditionally (AGP < 9) or provided by AGP's built-in Kotlin (AGP 9+). The +// static `kotlin { }` accessor is not generated for imperatively-applied plugins. +project.extensions.configure(org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension::class.java) { + compilerOptions { + jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 + } +} + +dependencies { + implementation("com.google.android.libraries.mapsplatform.transportation:transportation-driver:7.0.0") + implementation("androidx.startup:startup-runtime:1.2.0") + testImplementation("org.jetbrains.kotlin:kotlin-test") + testImplementation("io.mockk:mockk:1.13.9") + testImplementation("junit:junit:4.13.2") + testImplementation("org.robolectric:robolectric:4.11.1") +} diff --git a/android/settings.gradle.kts b/android/settings.gradle.kts index a8c90cd..f4e20b4 100644 --- a/android/settings.gradle.kts +++ b/android/settings.gradle.kts @@ -1,4 +1,4 @@ -// Copyright 2023 Google LLC +// Copyright 2026 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,4 +12,4 @@ // See the License for the specific language governing permissions and // limitations under the License. -rootProject.name = 'google_driver_flutter' +rootProject.name = "google_driver_flutter" diff --git a/example/android/app/build.gradle.kts b/example/android/app/build.gradle.kts index 258b387..1b2ba28 100644 --- a/example/android/app/build.gradle.kts +++ b/example/android/app/build.gradle.kts @@ -41,16 +41,12 @@ android { compileSdk = flutter.compileSdkVersion ndkVersion = "28.2.13676358" - compileOptions { + compileOptions { // Flag to enable support for the new language APIs isCoreLibraryDesugaringEnabled = true - // Sets Java compatibility to Java 11 - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 - } - - kotlinOptions { - jvmTarget = JavaVersion.VERSION_11.toString() + // Sets Java compatibility to Java 17 + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } // Set this to the languages you actually use, otherwise you'll include resource strings @@ -105,6 +101,14 @@ android { } } +// Configure the Kotlin JVM target via the compilerOptions DSL (replaces the deprecated +// android.kotlinOptions block). +kotlin { + compilerOptions { + jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 + } +} + flutter { source = "../.." } diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index ed4c299..7705927 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-all.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/example/android/settings.gradle.kts b/example/android/settings.gradle.kts index 2b72739..bf3e0ca 100644 --- a/example/android/settings.gradle.kts +++ b/example/android/settings.gradle.kts @@ -33,7 +33,7 @@ pluginManagement { plugins { id("dev.flutter.flutter-plugin-loader") version "1.0.0" id("com.android.application") version "8.13.0" apply false - id("org.jetbrains.kotlin.android") version "2.1.0" apply false + id("org.jetbrains.kotlin.android") version "2.3.20" apply false id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin") version "2.0.1" apply false } diff --git a/melos.yaml b/melos.yaml index fd3e54a..faa18f9 100644 --- a/melos.yaml +++ b/melos.yaml @@ -73,7 +73,7 @@ scripts: run: | if [ -d "example" ]; then cd example; fi && \ if [ ! -f android/gradlew ]; then flutter build apk --config-only; fi && - cd android && ./gradlew ktfmtFormat + cd android && ./gradlew -Pktfmt ktfmtFormat exec: concurrency: 1 failFast: true