Skip to content

[plugins] ☂️ Kotlin conversion for 1P plugins #188630

Open

Description

@stuartmorgan-g

IMPORTANT NOTE: Per the documented policy, PRs migrating existing code will only be accepted from Flutter team members.

I think there a number of compelling reasons that we should use Kotlin for all of our 1P plugins:

  • Maintenance benefits:
    • Kotlin is a safer language. Notably, it has strong type safety and null handling, like modern Dart, which eliminates whole categories of errors (errors which have caused bugs in our plugin for the entire time I have been on the ecosystem team). It also has a modern concurrency system that has safety benefits over callbacks, guaranteeing that an async operation doesn't have codepaths that complete anything other than exactly once (particularly important for method channels).
    • Kotlin is, IMO, more like Dart. The type system, concurrency system, collection operations, etc. are much more similar to Dart than Java's, which I find makes moving between them easier. For the ecosystem team, this is particularly valuable, as we deal with more languages, so the more similar they are the better (and Swift, which we are actively moving to is also more like Dart and Kotlin).
    • We plan to remove the Java Pigeon generator, and have therefore switched essentially all of our plugins to the Kotlin generator, so currently most plugins are hybrid. While the Kotlin code is generated rather than human-maintained, there are some mismatches that make the Java code slightly awkward, especially around Pigeon's use of the Result Kotlin type, leading to shims like this.
    • The build files for our plugins are all Kotlin now, so replacing Java with Kotlin would reduce the overall number of languages in the repo by one.
  • Community benefits:
    • The community often looks to our plugins as examples. The flutter create default for a new plugin has been Kotlin for many years now, so our Java code is not as useful an example for other developers.
    • Relatedly, if we want our plugins to serve as examples of good practices that LLMs will draw from, having them be in the language developers are likely to be using will make them more likely to positively influence generated code.
    • Our experience will better match the community's, shaping our development priorities in ways that better align with the community. For instance, I think it's very likely that we would have prioritized adopting modern concurrency in Pigeon's Swift and Kotlin generators if we had been using those languages, since historically Pigeon development has been driven mostly by our own actual usage.
    • To the extent that both our create defaults and Android's Kotlin-first model encourage Android plugin developers to learn Kotlin, not Java, having our plugin be Kotlin would make community contributions to our plugins (PRs, reviews, etc.) easier. (I would also expect that the increased safety would make reviewing easier in the long term.)

Potentially useful references:


Current status:

Activity

  1. added
    packageflutter/packages repository. See also p: labels.
    c: tech-debtTechnical debt, code quality, testing, etc.
    team-androidOwned by Android platform team
    on Jun 26, 2026
  2. stuartmorgan-g commented on Jun 26, 2026

    @stuartmorgan-g
    ContributorAuthor

    I also want to capture a suggestion here about an approach for migrating, which I trialed in local_auth as an experiment. This branch has the individual steps I took, which were:

    • Start by using the Android Studio auto-conversion tool to convert Java files to Kotlin (I did the whole plugin since it's small, but it could be done file by file in many cases due to the generally good interop between the two languages). My understanding is that this is a deterministic process, so not subject to the possibility of subtle regressions due to hallucinations that an LLM-based migration could introduce (something I have seen in trying to do LLM Obj-C to Swift conversions).
      • Commit this step before making any edits, to allow reviewers to see what changes are made after this point.
    • Do manual fix-up of the raw conversion:
      • Manually clean up compilation errors due to places where the auto-conversion didn't handle some code quite right. I found these pretty straightforward in local_auth.
      • Improve nullability handling. I found this fell into a couple of buckets:
        • Remove nullability from a lot of types. Because it's starting from Java code that is mostly not annotated, it will assume nullability in a lot of cases where that's not actually needed. This can of course be done incrementally later, but I found it a valuable way to improve the code's quality and understandability.
        • Audit any uses of !, and try to eliminate as many as possible. The previous step can clean up a lot of them, but what's left often exposes latent potential NPEs from our old Java code, where we were passing types that really were nullable into underlying APIs that don't allow nulls.
      • Address warnings raised in the IDE, since the generated code is likely not warning-free (especially since our Java code isn't warning-free)
    • Prompt a local agent to review the conversion, with a particular emphasis on pointing out places where the code could be made more idiomatic Kotlin. Look over its suggestions, and adopt anything that seems worthwhile.

    I found the last step valuable as a way to not only improve the code, but to help address one of the main reasons we haven't adopted Kotlin already: the Flutter team has a lot of Java experience, but not much Kotlin experience. Because we don't have veteran Kotlin reviewers, we haven't had a good bootstrapping mechanism for learning the Kotlin-y way to do something. An agent review helps fill that gap because common coding conventions are the kind of thing that LLMs are generally good at surfacing. In my trial, it raised several Kotlin features that I didn't know about, went and learned about, and then adopted, both making the code better and improving my knowledge of Kotlin.

    If/when the Android team decides to migrate, I would highly recommend having everyone working on plugins go through this process on a plugin or portion of a plugin (which, I think counterintuitively, means not leveraging the community to do most of the migration), as a way of getting everyone more comfortable with Kotlin.

  3. stuartmorgan-g commented on Jun 26, 2026

    @stuartmorgan-g
    ContributorAuthor

    Lastly, capturing the other main argument against this from previous discussions: since the engine is Java, the language consistency argument cuts the other way there. While this proposal reduces the number of languages in flutter/packages, it means everyone whose work is split between the engine and plugins (which I believe is the entire Android team) will increase the number of languages they regularly interact with (until/unless the engine also adopts Kotlin, but I would expect migrating that to be much harder than migrating individual plugins).

  4. added
    P2Important issues not at the top of the work list
    triaged-androidTriaged by Android platform team
    on Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: tech-debtTechnical debt, code quality, testing, etc.packageflutter/packages repository. See also p: labels.team-androidOwned by Android platform teamtriaged-androidTriaged by Android platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions