noise_meter: migrate Android build to Java 21 / Kotlin 21 (AGP 8.x compatibility) #1227
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR upgrades the Android build settings for packages/noise_meterfrom Java 8 to Java 21 so the plugin compiles cleanly on modern Flutter toolchains that ship with Android Gradle Plugin (AGP) 8 and Kotlin 2.
Key changes
In packages/noise_meter/android/build.gradle
compileOptions now sets sourceCompatibility and targetCompatibility to JavaVersion.VERSION_21.
Every KotlinCompile task now has kotlinOptions.jvmTarget = "21".
All lines that hard‑coded VERSION_1_8 or jvmTarget = "1.8" have been removed.
pubspec.yaml has its patch version bumped from 4.2.0 to 4.2.1 and notes the Java 21 migration in the description.
CHANGELOG.md records the upgrade and the build error it resolves.
Why this matters
Current releases of Flutter, Android Studio, AGP 8+ and Kotlin 2 default to Java 17 or higher. When the library’s Gradle script forces Java 8 while Kotlin or other modules emit Java 17/21 byte‑code, builds fail with
Execution failed for task ':noise_meter:compileDebugKotlin' — Inconsistent JVM‑target compatibility (1.8 vs 17/21).
Raising both Java and Kotlin targets to 21 removes that conflict, allowing apps to compile without per‑project work‑arounds.
Compatibility
No runtime behaviour changes—the produced APK/DEX remains compatible with the plugin’s existing minSdkVersion.
Building now requires JDK 21 or newer, which is the default JDK bundled with Android Studio 2025.1 and fully supported by AGP 8.4+.
Please review and merge so the community can build noise_meter seamlessly on current Flutter and Android Studio versions.