diff --git a/android/build.gradle b/android/build.gradle deleted file mode 100644 index eed4aa0..0000000 --- a/android/build.gradle +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2023 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// 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' - repositories { - google() - mavenCentral() - maven { url "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' - } -} - -allprojects { - repositories { - google() - mavenCentral() - } -} - -apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' -apply plugin: 'com.ncorti.ktfmt.gradle' - -ktfmt { - googleStyle() -} - -android { - if (project.android.hasProperty("namespace")) { - namespace 'com.google.maps.flutter.driver' - } - - compileSdk 36 - - compileOptions { - sourceCompatibility JavaVersion.VERSION_11 - targetCompatibility JavaVersion.VERSION_11 - } - - kotlinOptions { - jvmTarget = '11' - } - - sourceSets { - main.java.srcDirs += 'src/main/kotlin' - 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' - } - - testOptions { - unitTests { - includeAndroidResources = true - } - unitTests.all { - testLogging { - events "passed", "skipped", "failed", "standardOut", "standardError" - outputs.upToDateWhen {false} - showStandardStreams = true - } - } - } -} diff --git a/android/build.gradle.kts b/android/build.gradle.kts new file mode 100644 index 0000000..06a4c28 --- /dev/null +++ b/android/build.gradle.kts @@ -0,0 +1,124 @@ +// 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. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +buildscript { + val kotlinVersion = "2.3.20" + repositories { + google() + mavenCentral() + // 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:$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() + mavenCentral() + } +} + +// 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 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 { + namespace = "com.google.maps.flutter.driver" + + compileSdk = 36 + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + + sourceSets { + getByName("main") { + java.srcDirs("src/main/kotlin") + } + getByName("test") { + java.srcDirs("src/test/kotlin") + } + } + + defaultConfig { + minSdk = 26 + } + + testOptions { + unitTests { + 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 b/android/settings.gradle.kts similarity index 88% rename from android/settings.gradle rename to android/settings.gradle.kts index a8c90cd..f4e20b4 100644 --- a/android/settings.gradle +++ 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