From 6011250379cfeee6eacdb126caf1f67e44941fd8 Mon Sep 17 00:00:00 2001 From: ubxty Date: Mon, 8 Jun 2026 19:48:14 +0530 Subject: [PATCH] Migrate to built-in Kotlin Migrates the plugin to use built-in Kotlin per the official Flutter migration guide: https://docs.flutter.dev/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors AGP 9.0 will remove support for plugins that apply the Kotlin Gradle Plugin. This commit removes the legacy `apply plugin: "kotlin-android"` line and the KGP classpath from `android/build.gradle`, and the same from the example app's `example/android/app/build.gradle`. The example app builds cleanly with `flutter build apk --debug` on Flutter 3.44.1 with no KGP deprecation warnings for wakelock_plus. Bumps the minimum Flutter version to 3.44.0 and Dart SDK to 3.12.0, as required by the new `kotlin.compilerOptions` DSL. Fixes the warning: "Your app uses the following plugins that apply Kotlin Gradle Plugin (KGP)". --- wakelock_plus/CHANGELOG.md | 11 +++++++++++ wakelock_plus/android/build.gradle | 12 ++++++------ wakelock_plus/example/android/app/build.gradle | 11 ++++++----- wakelock_plus/example/android/gradle.properties | 2 ++ wakelock_plus/pubspec.yaml | 6 +++--- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/wakelock_plus/CHANGELOG.md b/wakelock_plus/CHANGELOG.md index da5027c..700ff89 100644 --- a/wakelock_plus/CHANGELOG.md +++ b/wakelock_plus/CHANGELOG.md @@ -1,3 +1,14 @@ +## [1.7.0] +* Migrate to built-in Kotlin per the official Flutter migration guide: https://docs.flutter.dev/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors +* Remove `apply plugin: "kotlin-android"` and KGP classpath from `android/build.gradle`. +* Remove `id 'kotlin-android'` and the `kotlinOptions` block from `example/android/app/build.gradle`. +* Add a top-level `kotlin { compilerOptions { jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 } }` block in both gradle files. +* Flip `android.builtInKotlin=true` and `android.newDsl=true` in `example/android/gradle.properties`. +* **BREAKING CHANGES**: + - Dart + * Library now requires Dart version `3.12` or higher. + * Library now requires Flutter version `3.44` or higher. + ## [1.6.1] * [#133](https://github.com/fluttercommunity/wakelock_plus/pull/133): wakelock_plus Flutter 3.38 downgrade. Thanks [diegotori](https://github.com/diegotori). - Library now requires Dart version `3.10` or higher, restoring previous compatibility. diff --git a/wakelock_plus/android/build.gradle b/wakelock_plus/android/build.gradle index d2a1ffe..ccdbaef 100644 --- a/wakelock_plus/android/build.gradle +++ b/wakelock_plus/android/build.gradle @@ -2,7 +2,6 @@ group 'dev.fluttercommunity.plus.wakelock' version '1.0-SNAPSHOT' buildscript { - ext.kotlin_version = '2.2.0' repositories { google() mavenCentral() @@ -21,7 +20,6 @@ rootProject.allprojects { } apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' android { namespace 'dev.fluttercommunity.plus.wakelock' @@ -32,9 +30,6 @@ android { targetCompatibility JavaVersion.VERSION_17 } - kotlinOptions { - jvmTarget = '17' - } lintOptions { disable 'InvalidPackage' } @@ -51,7 +46,6 @@ android { } dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" testImplementation 'org.jetbrains.kotlin:kotlin-test' testImplementation 'org.mockito:mockito-core:5.0.0' } @@ -69,3 +63,9 @@ android { } } } + +kotlin { + compilerOptions { + jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 + } +} diff --git a/wakelock_plus/example/android/app/build.gradle b/wakelock_plus/example/android/app/build.gradle index c53cd6c..ec1f16c 100644 --- a/wakelock_plus/example/android/app/build.gradle +++ b/wakelock_plus/example/android/app/build.gradle @@ -1,6 +1,5 @@ plugins { id 'com.android.application' - id 'kotlin-android' id 'dev.flutter.flutter-gradle-plugin' } def localProperties = new Properties() @@ -31,10 +30,6 @@ android { targetCompatibility JavaVersion.VERSION_17 } - kotlinOptions { - jvmTarget = '17' - } - sourceSets { main.java.srcDirs += 'src/main/kotlin' } @@ -65,3 +60,9 @@ flutter { dependencies { } + +kotlin { + compilerOptions { + jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 + } +} diff --git a/wakelock_plus/example/android/gradle.properties b/wakelock_plus/example/android/gradle.properties index bee0af8..be75b14 100644 --- a/wakelock_plus/example/android/gradle.properties +++ b/wakelock_plus/example/android/gradle.properties @@ -1,3 +1,5 @@ org.gradle.jvmargs=-Xmx4g android.useAndroidX=true android.enableJetifier=true +android.builtInKotlin=true +android.newDsl=true diff --git a/wakelock_plus/pubspec.yaml b/wakelock_plus/pubspec.yaml index a555046..f649171 100644 --- a/wakelock_plus/pubspec.yaml +++ b/wakelock_plus/pubspec.yaml @@ -2,12 +2,12 @@ name: wakelock_plus description: >-2 Plugin that allows you to keep the device screen awake, i.e. prevent the screen from sleeping on Android, iOS, macOS, Windows, Linux, and web. -version: 1.6.1 +version: 1.7.0 repository: https://github.com/fluttercommunity/wakelock_plus/tree/main/wakelock_plus environment: - sdk: '>=3.10.0 <4.0.0' - flutter: ">=3.38.0" + sdk: ^3.12.0 + flutter: '>=3.44.0' dependencies: flutter: