Skip to content

Migrate Android build to built-in Kotlin and align with the Flutter 3.44 toolchain - #150

Merged
onevcat merged 2 commits into
masterfrom
feature/builtin-kotlin-migration
Jul 23, 2026
Merged

Migrate Android build to built-in Kotlin and align with the Flutter 3.44 toolchain#150
onevcat merged 2 commits into
masterfrom
feature/builtin-kotlin-migration

Conversation

@onevcat

@onevcat onevcat commented Jul 23, 2026

Copy link
Copy Markdown
Member

Summary

  • Supersedes Align Android build with Flutter 3.35.7 toolchain #134, fixes Migrate Plugin to Built-in Kotlin #148.
  • Commit 1 aligns the Android toolchain of the plugin and the example app with current Flutter stable (3.44.7): AGP 8.11.1, Kotlin 2.2.20, Gradle 8.14, compileSdk 36, Java 17, coroutines 1.8.1. The old toolchain was below Flutter 3.44's hard minimums (Gradle 8.7 / AGP 8.6), so the example no longer built on stable at all.
  • Commit 2 completes the migration to Flutter's built-in Kotlin: the plugin no longer applies KGP, android.kotlinOptions moves to the top-level kotlin.compilerOptions, and both projects adopt the Flutter 3.44 template versions (AGP 9.0.1 / Kotlin 2.3.20 / Gradle 9.1.0). This raises the requirement to Flutter >= 3.44.0 / Dart >= 3.12.0.

Because of the new Flutter minimum, this should ship as a major release (3.0.0), keeping 2.x available for users on older Flutter — as also suggested in the discussion on #134. Version bump and CHANGELOG will be handled by the usual release flow after merge.

Why the AGP-version guard was not enough

The if (agpMajor < 9) { apply plugin: 'kotlin-android' } guard on master turned out to be insufficient, in two ways (verified against the flutter_tools source and reproduced locally on 3.44.7):

  1. Flutter's migration check scans the Gradle script text line by line (kgpRegexGroovy in FlutterPluginUtils.kt), so the guarded apply still counts as "plugin applies KGP" and triggers the warning reported in Migrate Plugin to Built-in Kotlin #148 whenever the app runs AGP 9+.
  2. Worse, under AGP 9 the two mechanisms contradict each other at runtime: the guard skips applying KGP, while the text scan makes Flutter believe the plugin applies it on its own — so Flutter does not apply it either. The plugin's Kotlin sources are then never compiled and the app build fails with:
error: cannot find symbol
      flutterEngine.getPlugins().add(new com.linecorp.flutter_line_sdk.FlutterLineSdkPlugin());

This is exactly the build failure class reported in #148. After this migration, Flutter applies KGP to the plugin project itself and :flutter_line_sdk:compileDebugKotlin runs again.

Verification (all local, Flutter 3.44.7 stable / Xcode 27 / macOS)

Check Result
master example vs Flutter 3.44.7 ❌ fails to configure (Gradle 8.6 < min 8.7; AGP 8.4 < min 8.6) — motivation for commit 1
Guarded plugin + AGP 9.0.1 example (state between the commits) ❌ reproduces the #148 warning (plugins that apply KGP: flutter_line_sdk) and fails with the missing-symbol error above
This PR, gradlew assembleDebug + flutter build apk (debug & release) ✅ builds, :flutter_line_sdk:compileDebugKotlin executed, zero KGP/deprecation warnings from Flutter
flutter analyze --fatal-infos / flutter test ✅ clean / 7 passed (same commands as CI)
Old Flutter negative test (3.41.6, Dart 3.11.4) pub get fails fast with a clear constraint message suggesting Flutter 3.44.7

Notes

  • The example app picks up a few Flutter/AGP auto-migrations along the way: gradle.properties flags (android.newDsl=false, android.builtInKotlin=false, matching what flutter create generates on 3.44), removal of the manifest package attribute (ignored since AGP 9), SPM package references added to the Xcode project by the Flutter tool, and use_super_parameters lint fixes surfaced by the Dart language version bump.
  • Out of scope, noticed during verification: Flutter 3.44 warns that ios/flutter_line_sdk/Package.swift is missing a FlutterFramework dependency under the new SPM plugin guideline — worth a small follow-up PR. Also, Xcode 27 (beta) raises the minimum deployment target to 15.0, so the example iOS app fails its integrity check there; both pre-exist on master and are unrelated to the Android migration.

🤖 Generated with Claude Code

onevcat and others added 2 commits July 23, 2026 09:51
Supersedes the version alignment part of #134, updated to the versions
current Flutter stable (3.44.7) expects:

- AGP 7.3.1 -> 8.11.1, Kotlin 1.7.21 -> 2.2.20, Gradle wrapper -> 8.14
  for both the plugin and the example app
- compileSdk 33 -> 36, Java 8 -> 17, coroutines 1.0.1 -> 1.8.1
- Remove the legacy buildscript block from the example root
  build.gradle (AGP/KGP are declared in settings.gradle since the
  project moved to the plugins DSL)
- Let the example track Flutter's compileSdk/targetSdk defaults
- gradle.properties flags added by the Flutter 3.44 auto-migrator

The old toolchain was below Flutter 3.44's minimum supported versions
(Gradle 8.7 / AGP 8.6), so the example failed to build on current
stable.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Fixes the incomplete built-in Kotlin migration reported in #148.

Flutter 3.44+ applies the Kotlin Gradle plugin (KGP) to plugin projects
itself. The previous AGP-version guard around `apply plugin:
'kotlin-android'` did not help, because Flutter's migration check scans
the Gradle script text: the guarded apply still triggered the "plugins
that apply KGP" warning under AGP 9. Worse, at runtime the guard
skipped applying KGP while the text scan made Flutter treat the plugin
as self-applying, so the plugin's Kotlin sources were never compiled
and app builds failed with "cannot find symbol: FlutterLineSdkPlugin".

Following the official plugin-author migration guide
(https://docs.flutter.dev/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors):

- Remove the KGP apply and the AGP version guard from the plugin build;
  KGP stays on the buildscript classpath, matching the Flutter plugin
  template
- Replace android.kotlinOptions with top-level kotlin.compilerOptions
- Require Flutter >=3.44.0 / Dart >=3.12.0 in pubspec
- Align plugin and example with Flutter 3.44 templates: AGP 9.0.1,
  Kotlin 2.3.20, Gradle 9.1.0
- Example: drop the app-level kotlin-android plugin id, remove the
  manifest package attribute (ignored since AGP 9), fix
  use_super_parameters lints surfaced by the language version bump,
  include Flutter tool auto-migrations (gradle.properties flags, SPM
  package references in the Xcode project)
- Document the new Flutter version requirement in README

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@onevcat
onevcat merged commit 1cd293a into master Jul 23, 2026
2 checks passed
@onevcat
onevcat deleted the feature/builtin-kotlin-migration branch July 23, 2026 02:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate Plugin to Built-in Kotlin

1 participant