Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Vinted Engineering 6 min read Case study mediumAdept

From Dagger to Metro

Vinted's Android team migrated a codebase of several hundred Gradle modules from Dagger, dagger.android and Anvil to Metro, a Kotlin compiler-plugin DI framework, mainly to escape Anvil's K1 lock-in and enable K2 and incremental compilation. They did a big-bang migration without Metro's interop layer: scripted regex replacements for annotations, KSP-generated graph extensions to replace 100+ dagger.android fragment injectors, and updates to existing codegen. Pain points included compiler crashes and slow generated code on 0.x versions (mostly from member injection), stray javax.inject imports, and daily upstream merge conflicts. CI builds got 6–26% faster, with local builds improving further from incremental compilation.

Assumes: Dagger dependency injectionKotlin compiler pluginsGradle multi-module builds

Related posts

  • Extending Anvil for Fun and Profit

    Slack Engineering hardMaster

    Slack's Android app replaced dagger-android activity injection with a custom Anvil code generator: annotating an activity with @InjectWith(scope) generates an AnvilInjector wrapping Dagger's intrinsic MembersInjector plus a @ContributesTo binding module that adds it to a scope-level multibinding map. BaseActivity looks up the injector from the scoped component in onCreate() and calls inject(). Built on Anvil 2.3.0's compiler-api, it runs inside kotlinc with no kapt or dagger-android-processor, avoids runtime reflection, and generalizes to any member-injected type such as services and jobs. Anvil's factory generation alone cut incremental build times by up to 25%.

  • It’s a non-transitive R class world

    Slack Engineering mediumAdept

    Slack migrated its 400+ module Android codebase to non-transitive R classes, where each module's R class contains only its own resources, yielding ~14% faster incremental builds after resource or layout changes and an ~8.5% (about 5.5MB) APK/DEX size reduction. Because Android Studio's built-in migration refactor stalled at this scale, the team used regex find-and-replace on the two modules holding most resources, a script to add Kotlin import aliases (e.g. L10nR, SlackKitR), and then enabled android.nonTransitiveRClass and android.enableAppCompileTimeRClass. Shared live templates and three auto-fixing lint checks enforce consistent alias conventions, and the migration also exposed misplaced resources and made resource origins easier to trace.

  • From zero to 10 million lines of Kotlin

    Meta Engineering mediumAdept

    Meta has converted its Android codebase to over 10 million lines of Kotlin by wrapping JetBrains' J2K converter in an automated pipeline called Kotlinator. The pipeline preprocesses Java packages, runs J2K headlessly through Android Studio, then applies automated refactors and linters built on the Kotlin compiler's PSI AST. Those refactors fix issues such as JUnit @Rule annotations needing @JvmField or @get:Rule, and replace TextUtils.isEmpty with isNullOrEmpty. Meta chose a full conversion over Kotlin-for-new-code-only to avoid platform-type null risks from Java interop. Results: about 11% fewer lines, no runtime performance regression in A/B tests, negligible APK size impact after Proguard/Redex, and longer build times as the main cost.

  • Enabling Kotlin incremental compilation on Buck2

    Meta Engineering mediumAdept

    Meta integrated the Kotlin incremental compiler into Buck2 via Kotlin's experimental Build Tools API, making some large Android modules build up to 3x faster and improving incremental build times about 30% for the average developer. The work involved migrating the toolchain to the shaded kotlin-compiler-embeddable, using Buck2 incremental actions to keep prior outputs and compute changed-file lists from input hashes, making the cache relocatable for remote execution, and generating classpath snapshots as a separate cacheable action. Custom compiler plugins had to be made incremental and accumulate results across multiple compilation rounds. jvm-abi-gen still lacks incremental support, so a stopgap merges the new ABI with the previous output.

  • Translating Java to Kotlin at Scale

    Meta Engineering mediumAdept

    Meta is translating roughly ten million lines of Android Java to Kotlin using the Kotlinator, an automated pipeline built around a headless version of JetBrains' J2K. It runs six phases: a deep build, about 50 preprocessing steps, headless J2K, about 150 postprocessing steps, linters with autofixes, and fixes driven by compiler errors. A daily cron system produces the conversion diffs for human review. Null safety comes first, because Kotlin inserts runtime null checks at the Java interop boundary, so the Kotlinator errs toward nullable types to avoid introducing new NPEs. Meta is also working with JetBrains to add extension hooks to J2K for better symbol resolution and to open-source some of its steps.

The quest for software engineering knowledge.

Look:
Layout: