diff --git a/CHANGELOG.md b/CHANGELOG.md index a712696..c05c793 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,21 @@ +## 0.5.2 + +* Support Android Gradle Plugin 9 and Flutter's built-in Kotlin mode while keeping + AGP 8 and Flutter's temporary `android.builtInKotlin=false` opt-out working. +* Stop declaring plugin-owned Android Gradle Plugin and Kotlin Gradle Plugin classpaths. +* Update the example Android app to Android Gradle Plugin 9.1.1. +* Tested example integration tests with: + + | Flutter | AGP | Kotlin mode | + | --- | --- | --- | + | 3.44.4 stable | 9.1.1 | Flutter AGP 9 opt-out | + | 3.44.0 | 9.1.1 | Flutter AGP 9 opt-out | + | 3.41.9 | 8.13.2 | legacy KGP | + | 3.35.7 | 8.13.2 | legacy KGP | + | 3.32.8 | 8.13.2 | legacy KGP | + +* Thanks to @raph5640, @amanvishwakarma96, and @Joschiller for reporting the AGP 9 build problem. + ## 0.5.1 * Add integration tests to verify plugin functionality across Android API levels diff --git a/README.md b/README.md index 842b8f1..7260e2c 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,23 @@ try { **Note:** `getId()` returns `null` on non-Android platforms (iOS, Web, etc.). On Android, it throws `MissingPluginException` if the plugin is not properly registered (see more [below](https://pub.dev/packages/android_id#troubleshooting)). +## Android build compatibility + +`android_id` supports Android Gradle Plugin 9 and Flutter's built-in Kotlin mode. +It also keeps working with AGP 8 and Flutter's temporary +`android.builtInKotlin=false` opt-out. + +The plugin no longer provides its own Android Gradle Plugin or Kotlin Gradle +Plugin classpaths. It only applies the Kotlin Gradle Plugin when the host build +still needs it. This fixes errors such as: + +```text +The 'org.jetbrains.kotlin.android' plugin is no longer required for Kotlin +support since AGP 9.0. +``` + +Most Flutter apps should not need app-code changes. + ## Important Please note that on `Android 8` and above, the `Android ID` is not unique per device, but also per signing key the app was built with: diff --git a/android/build.gradle b/android/build.gradle index 701bcac..1cdb33c 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,19 +1,6 @@ group = "dev.fluttercommunity.android_id" version = "1.0-SNAPSHOT" -buildscript { - ext.kotlin_version = "2.1.0" - repositories { - google() - mavenCentral() - } - - dependencies { - classpath("com.android.tools.build:gradle:8.7.2") - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version") - } -} - allprojects { repositories { google() @@ -22,7 +9,19 @@ allprojects { } apply plugin: "com.android.library" -apply plugin: "kotlin-android" + +def agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0] as int +boolean hasBuiltInKotlinSupport = agpMajor >= 9 + +def builtInKotlinProperty = findProperty('android.builtInKotlin') +boolean isBuiltInKotlinEnabled = builtInKotlinProperty == null || + builtInKotlinProperty.toString().toBoolean() + +boolean shouldApplyKotlinGradlePlugin = !hasBuiltInKotlinSupport || !isBuiltInKotlinEnabled + +if (shouldApplyKotlinGradlePlugin) { + apply plugin: 'kotlin-android' +} android { if (project.android.hasProperty("namespace")) { @@ -36,10 +35,6 @@ android { targetCompatibility = JavaVersion.VERSION_17 } - kotlinOptions { - jvmTarget = "17" - } - sourceSets { main.java.srcDirs += "src/main/kotlin" test.java.srcDirs += "src/test/kotlin" @@ -66,3 +61,9 @@ android { } } } + +kotlin { + compilerOptions { + jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 + } +} diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 3ab4a50..5bed1cb 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -1,7 +1,6 @@ plugins { id "com.android.application" - id "kotlin-android" - // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. + // The Flutter Gradle Plugin must be applied after the Android Gradle plugin. id "dev.flutter.flutter-gradle-plugin" } @@ -33,10 +32,6 @@ android { targetCompatibility = JavaVersion.VERSION_17 } - kotlinOptions { - jvmTarget = "17" - } - defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId = "dev.fluttercommunity.android_id_example" @@ -60,3 +55,9 @@ android { flutter { source = "../.." } + +kotlin { + compilerOptions { + jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 + } +} diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index 6b74f0f..bdc0141 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip diff --git a/example/android/settings.gradle b/example/android/settings.gradle index 72e8d42..6464403 100644 --- a/example/android/settings.gradle +++ b/example/android/settings.gradle @@ -18,8 +18,7 @@ pluginManagement { plugins { id "dev.flutter.flutter-plugin-loader" version "1.0.0" - id "com.android.application" version "8.7.2" apply false - id "org.jetbrains.kotlin.android" version "2.1.0" apply false + id "com.android.application" version "9.1.1" apply false } include ":app" diff --git a/example/pubspec.lock b/example/pubspec.lock index b750e42..fcd208e 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: path: ".." relative: true source: path - version: "0.5.1" + version: "0.5.2" async: dependency: transitive description: @@ -28,10 +28,10 @@ packages: dependency: transitive description: name: characters - sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803 + sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b url: "https://pub.dev" source: hosted - version: "1.4.0" + version: "1.4.1" clock: dependency: transitive description: @@ -133,26 +133,26 @@ packages: dependency: transitive description: name: matcher - sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2 + sha256: dc0b7dc7651697ea4ff3e69ef44b0407ea32c487a39fff6a4004fa585e901861 url: "https://pub.dev" source: hosted - version: "0.12.17" + version: "0.12.19" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec + sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b" url: "https://pub.dev" source: hosted - version: "0.11.1" + version: "0.13.0" meta: dependency: transitive description: name: meta - sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c + sha256: "1741988757a65eb6b36abe716829688cf01910bbf91c34354ff7ec1c3de2b349" url: "https://pub.dev" source: hosted - version: "1.16.0" + version: "1.18.0" path: dependency: transitive description: @@ -234,10 +234,10 @@ packages: dependency: transitive description: name: test_api - sha256: "522f00f556e73044315fa4585ec3270f1808a4b186c936e612cab0b565ff1e00" + sha256: "949a932224383300f01be9221c39180316445ecb8e7547f70a41a35bf421fb9e" url: "https://pub.dev" source: hosted - version: "0.7.6" + version: "0.7.11" vector_math: dependency: transitive description: @@ -263,5 +263,5 @@ packages: source: hosted version: "3.1.0" sdks: - dart: ">=3.8.0 <4.0.0" + dart: ">=3.10.0-0 <4.0.0" flutter: ">=3.18.0-18.0.pre.54" diff --git a/pubspec.yaml b/pubspec.yaml index 0fb9dc2..a49f986 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -13,7 +13,7 @@ topics: - android - native -version: 0.5.1 +version: 0.5.2 environment: sdk: '>=3.0.0 <4.0.0'