Why Meta Swapped Java for Kotlin: Insights from a Massive Android Migration

Meta’s recent shift of its Android apps from Java to Kotlin reveals both the compelling benefits—such as null‑safety, concise code, and functional features—and the practical challenges like mixed codebases, tooling gaps, and longer build times, offering a detailed roadmap for large‑scale mobile language migration.

Programmer DD
Programmer DD
Programmer DD
Why Meta Swapped Java for Kotlin: Insights from a Massive Android Migration

Meta published a blog announcing the migration of its Android applications from Java to Kotlin, sharing the experience and lessons learned.

The company argues that Kotlin, a popular Android development language, offers key advantages over Java, including nullability safety, functional programming support, shorter code, and domain‑specific language (DSL) / type‑safe builders. In the latest Stack Overflow developer survey, Kotlin’s favorability surpasses Java’s.

Facebook engineer Omer Strulovich noted that several Meta Android apps—Facebook, Instagram, Messenger, Portal, and Quest—have already transitioned, with each exceeding one million lines of Kotlin code and the overall Android codebase now containing over ten million Kotlin lines. Meta also open‑sourced various examples and utilities for working with Kotlin code.

However, the migration presents drawbacks: maintaining a mixed Java/Kotlin codebase is time‑consuming, Kotlin’s ecosystem has fewer tools compared to Java, and interoperability adds complexity. Build times are notably longer because Kotlin’s compiler and ecosystem are less mature after two decades of Java optimization.

How to Handle Migration

Meta considered two options before migrating:

Write new code in Kotlin while keeping most existing code in Java.

Convert almost all internal code to Kotlin.

The first option reduces effort but introduces two major issues: platform types required for Java‑Kotlin interop can cause runtime null‑pointer crashes, and Kotlin’s overload rules differ from Java’s, leading to potential type‑safety problems. Additionally, Java cannot mark type parameters as nullable, and Kotlin’s overload resolution considers nullability, unlike Java.

The second option was chosen despite the challenge that most of Meta’s software is Java‑based, making a full conversion labor‑intensive. During the transition, Meta faced problems such as updating Redex to support bytecode patterns not generated by Java, and internal libraries that rely on compile‑time bytecode transformations that do not work when Kotlin compiles.

Meta also addressed tooling gaps: they upgraded the Pygments library for Kotlin syntax highlighting, updated internal code‑modification tools, and built Ktfmt, a deterministic Kotlin formatter based on google-java-format.

After preparing these tools, Meta began bulk converting code. Over 10 million lines of Kotlin have been added, and the migration has reduced overall code size by about 11 %. Most Android developers at Meta now write Kotlin.

The migration is ongoing and accelerating. Meta encourages any Android developer who wants to use Kotlin to do so, providing tools to simplify the conversion. While Kotlin still lacks some tools and optimizations familiar from Java, Meta is actively narrowing the gap and plans to share improvements with the broader community.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaMobile DevelopmentAndroidKotlincode migrationMeta
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.