Skip to content

fix: migrate Android plugin to built-in Kotlin (AGP 9) - #409

Open
Cherubins-App wants to merge 1 commit into
customerio:mainfrom
Cherubins-App:fix/built-in-kotlin
Open

Cherubins-App wants to merge 1 commit into
customerio:mainfrom
Cherubins-App:fix/built-in-kotlin

Conversation

@Cherubins-App

Copy link
Copy Markdown

Fixes #343. Supersedes the #344 spike, which predates the Compose plugin added for the inbox and now conflicts with main.

Changes

Following Flutter's migration guide for plugin authors:

  • Stop applying kotlin-android. With AGP 9+, Kotlin is built into AGP. With AGP < 9 (or android.builtInKotlin=false), Flutter ≥ 3.44 applies it to the plugin.
  • Replace android.kotlinOptions and the per-task kotlinOptions with the top-level kotlin { compilerOptions { … } } block. Opt-ins now use optIn instead of the deprecated -Xopt-in.
  • Raise the Flutter floor to >=3.44.0, as the guide requires. CI already uses 3.44.8. The Dart sdk constraint is unchanged, so the package's language version does not change.

About the Flutter floor

Projects on Flutter < 3.44 are not broken: pub keeps them on 4.5.0. In practice, 4.5.0 already needs a recent AGP 8 (compileSdk 36, Java 17, KGP 2.1, Compose), so the current >=2.5.0 floor is no longer accurate.

If you'd rather keep the floor for a transitional release, there is an alternative. It builds under the same setups listed below, and I'm happy to switch the PR to it:

apply plugin: 'com.android.library'
if (project.extensions.findByName('kotlin') == null) {
    apply plugin: 'kotlin-android'
}

It only postpones the migration, though. Flutter detects KGP usage by matching apply plugin: 'kotlin-android' in the build file with a regex (FlutterPluginUtils.kt), even inside an if. customer_io would stay in the "Future versions of Flutter will fail to build if your app uses plugins that apply KGP" warning, and the floor bump would be needed once that warning becomes an error.

Verification

Flutter 3.47.4, run locally: fork PRs don't get the secrets used by the sample-app build workflow.

Setup Before After
Production app (Firebase, RevenueCat, …), AGP 9.3.2 / Gradle 9.7.1, builtInKotlin=true Failed to apply plugin 'org.jetbrains.kotlin.android' ✅ built, plugin compiled by AGP's built-in Kotlin
Same app, builtInKotlin=false
Fresh flutter create app downgraded to AGP 8.11.1 / KGP 2.2.20 / Gradle 8.14.3
:customer_io:testDebugUnitTest under built-in Kotlin ✅ 14 tests, 0 failures
flutter pub publish --dry-run

After the change, Flutter's KGP warning no longer lists customer_io.

The sample apps are left on AGP 8 with builtInKotlin=false. Moving them to AGP 9 depends on their other plugins (the source of the #344 CI failures) and is better done separately.

Stop applying kotlin-android and move Kotlin compiler options to the
top-level compilerOptions block, following Flutter's migration guide for
plugin authors. Raise the Flutter floor to 3.44, the first version that
applies KGP to plugins on AGP < 9.
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

2 participants