Kgp warning - #3984
Conversation
- Updated SentryNativeJava class to use new native methods for display refresh rate and replay ID. - Refactored dartToJObject, dartToJList, dartToJStringList, and dartToJMap functions for improved type handling. - Enhanced initSentryAndroid function to utilize new native methods for application context and options configuration. - Updated session replay configuration to use new properties and methods. - Changed jni and jnigen dependencies to newer versions in pubspec.yaml. - Added exclusion patterns for analysis in isar and sqflite packages. - Updated melos version in the root pubspec.yaml. - Introduced gradle-daemon-jvm.properties for toolchain configuration. - Fixed comment in utf8_json_test.dart for clarity.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a2e8d9e. Configure here.
| } | ||
| } | ||
|
|
||
| val kotlinVersion = "2.3.10" |
There was a problem hiding this comment.
Buildscript pins break older AGP
High Severity
The plugin buildscript now hardcodes AGP 9.3.2 and KGP 2.3.10, and still applys that KGP whenever built-in Kotlin is off. AGP 9.3 requires Gradle 9.5, while min_version_test stays on Gradle 8.2 / AGP 8.1.4 / Kotlin 1.8.0. That path is the PR’s claimed AGP < 9 support, but it was not verified and is likely to fail or load mismatched Kotlin plugins for older consumers.
Additional Locations (2)
Triggered by project rule: PR Review Guidelines for Cursor Bot (Root)
Reviewed by Cursor Bugbot for commit a2e8d9e. Configure here.
|
KGP 9 support has already been merged, it will be part of the next release |


fix(flutter): Stop tripping Flutter's built-in Kotlin (KGP) warning on Android
📜 Description
Apps on recent Flutter versions that depend on
sentry_fluttersee this on every Android build:This PR migrates
packages/flutter/androidto AGP 9's built-in Kotlin so the warning goes away, while keeping support for apps still on AGP < 9.The key detail is how Flutter detects this. It does not inspect the build at runtime — it runs a regex over the plugin's build script source text (
FlutterPluginUtils.getSubprojectPluginState), and says so explicitly:That has a consequence worth calling out: a runtime guard is not enough. Any Groovy build file containing a line that starts with
apply plugin: 'kotlin-android'is flagged, even when that line is unreachable. Flutter's Kotlin DSL regex, by contrast, only matches KGP inside aplugins {}block and deliberately ignoresapply(plugin = ...)— which is exactly the conditional shape Flutter's own plugin author migration guide recommends for plugins that still support older AGP.So
packages/flutter/android/build.gradleis converted tobuild.gradle.kts:android.builtInKotlinis honored alongside the AGP version, because that flag lets a consuming app opt back out of built-in Kotlin (Flutter's own migrator adds it).Other changes in the Kotlin DSL port:
jvmTargetis set via KGP 2.x'scompilerOptionsDSL, with a reflection-based fallback tokotlinOptionsfor KGP 1.8.x (still shipped by Flutter 3.24-era apps and used bymin_version_test). The fallback uses reflection specifically so it cannot fail to compile or throw against a KGP whose types differ from those the script was compiled against.src/main/kotlinsrcDir is dropped — both the standalone Kotlin plugin and AGP 9's built-in Kotlin register it by convention.targetSdkVersionis dropped from the library'sdefaultConfig; it has no effect on an AAR and is deprecated for libraries.Android toolchain updates
Plugin (
packages/flutter/android):The example app is brought in line (Gradle 8.14.3 → 9.5.0, AGP 8.11.1 → 9.3.2, KGP 2.2.20 → 2.3.10, SDK 36 → 37). The
KOTLIN_ANDROID_PLUGIN_VERSION/ANDROID_GRADLE_PLUGIN_VERSIONenv overrides are untouched, so thekotlin-version-compatibilitymatrix still drives both KGP versions.AGP 9 needed five further fixes in the example, each a hard error rather than a warning:
android.enableR8=trueremoved fromgradle.properties(removed in AGP 7;truewas already the default, so this is behavior-neutral).getDefaultProguardFile('proguard-android.txt')→'proguard-android-optimize.txt'; AGP 9 rejects the non-optimizing file. This does enable R8 optimizations for the example's release build.1.8→2.3; KGP 2.3.10 dropped language version 1.8 outright.android:extractNativeLibs="true"moved out ofAndroidManifest.xmlintopackagingOptions.jniLibs.useLegacyPackaging = true. AGP 9 only accepts it from the build script; the behavior is preserved because sentry-native's crash handler relies on it.io.sentry:sentry-native-ndkpinned to0.16.2. AGP 9 resolves Prefab from the compile classpath, but the transitive copy isruntime-scoped insentry-android-ndk's POM, so the previous versionless declaration resolved tosentry-native-ndk:with an empty version. Removing the direct declaration instead is not an option —find_package(sentry-native-ndk REQUIRED CONFIG)then fails.The example's
package_info_plusmoves^4.0.0→^10.0.0: 4.2.0 hardcodescompileSdkVersion 33, which AGP 9's AAR metadata check rejects against modern AndroidX, and its own Kotlin source does not compile against API 34+. The SDK's own constraint is>=1.0.0, so only the example moves;min_version_testkeeps its deliberate8.3.1pin.JNI bindings regenerated for
jni1.xjni0.14.2 → ^1.0.3 andjnigen0.14.2 → ^0.17.0, withbinding.dartregenerated. jnigen 0.17 emits extension types instead of classes and turns JavagetX()/setX()/isX()pairs into Dart properties, so all call sites were updated (opts.setDsn(x)→opts.dsn = x,opts.isDebug()→opts.isDebug). Otherjni1.x API changes handled:JList.array/JMap.hash→JArrayList/JHashMap;JList/JMap/JSetno longer implement Dart's collection types, so[]/.length/.mapgo through.asDart();JByteArray.from→.of;releaseOriginal:dropped from the boxed-primitive accessors.💡 Motivation and Context
Flutter has announced that future versions will fail to build when an app depends on a plugin that applies KGP, so this is a forward-compatibility fix, not just noise reduction. Every app using
sentry_fluttercurrently prints the warning on each Android build and is pointed at us to fix it.The AGP 9 / Gradle 9.5 toolchain bump is a prerequisite: built-in Kotlin only exists on AGP 9+.
💚 How did you test it?
Verified locally on Windows with the example app (
packages/flutter/example):flutter clean+flutter build apk --debugon the convertedbuild.gradle.kts— zero occurrences of the KGP warning in the build log, where the same build on the previous Groovy file printed it.:sentry_flutterat runtime (AGP 9, built-in Kotlin active) and Flutter still warned — proving detection is source-text only. Collapsing the guard onto one line made the warning vanish with no behavioral change, isolating the regex as the sole cause.flutter build apk --debug --target-platform=android-x64— passes (clean and incremental).flutter build apk --release --target-platform=android-arm64— passes, exercising R8 with the changed ProGuard file (13.9 MB APK).kotlin-version-compatibilitylow-end combo (KOTLIN_ANDROID_PLUGIN_VERSION=2.2.20,KOTLIN_LANGUAGE_VERSION=1.8) against AGP 9.3.2 — passes, so that workflow is not broken by the new defaults.jvmTargetis genuinely applied: compiledSentryFlutterPlugin.classhas class-file major version 52 (Java 8).dart analyzeclean acrosspackages/flutterandpackages/flutter/example(was 3175 issues mid-migration).flutter testinpackages/flutter: 1081 passing. The 5 failures intest/sentry_native/sentry_native_test.dartarecmakenot being on PATH in my environment, unrelated to these changes.Not verified locally — please confirm in CI:
min_version_test(Gradle 8.2 / AGP 8.1.4 / Kotlin 1.8.0). It caps at JDK 20 and this machine only has JDK 21/25/26, so thekotlinOptionsreflection fallback and theapply(plugin = ...)branch under AGP 8 were not exercised end-to-end. The AGP < 9apply(plugin = ...)path was exercised on AGP 9 viaandroid.builtInKotlin=false, and the KGP 2.xcompilerOptionspath was exercised on both KGP 2.2.20 and 2.3.10.📝 Checklist
sendDefaultPiiis enabledNotes on the unchecked boxes:
package_info_plusmajor bump may warrant a changelog note. Both need a maintainer's call on the compatibility policy.binding.dartis regenerated wholesale, so the Java-facing internal surface changed shape.🔮 Next steps
min_version_testand the fullkotlin-version-compatibilitymatrix pass in CI.binding.dartcarries four hand-edits that regeneration will silently drop. jnigen 0.17.0 emits a nullable getter beside a non-null setter wherever sentry-java annotates only the setter parameter@NotNull, which is a Dart compile-time error (// ignoredoes not help — confirmed withdart compile kernel). Four setters were widened to accept null:SentryAndroidOptions.beforeScreenshotCaptureCallback,SentryAndroidOptions.beforeViewHierarchyCaptureCallback,SentryOptions.gestureTargetLocators,SentryEvent.timestamp. Worth an upstream jnigen issue.applyis flagged in Groovy but not in Kotlin DSL) is arguably a Flutter bug and may be worth reporting upstream.27.2.12479018whilejni1.x wants28.2.13676358; Flutter warns but the build succeeds. Bumping it would also make the-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ONr27 workaround redundant.