Skip to content

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

Slack Engineering 6 min read Case study hardMaster

Extending Anvil for Fun and Profit

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%.

Related posts

  • Scaling Slack’s Mobile Codebases: Modularization

    Slack Engineering mediumAdept

    Slack split its monolithic iOS and Android app targets into owned Feature, Service and Library modules with strict linking rules, such as interface/implementation pairs on iOS, to cut build times, untangle dependencies and clarify code ownership. On iOS, adopting Bazel made module creation easy, eliminated project-file merge conflicts, enabled static linking that improved pre-main launch time, and powered code generation for modules, CoreData models and feature flags. On Android, Slack abandoned a per-module Dagger 'graph of graphs' in favor of Square's Anvil, cut KAPT usage by moving to KSP, Moshi and Kotlin data classes, and enabled Gradle configuration caching, saving 20-45s on builds after configuration changes.

  • 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.

  • Scaling Slack’s Mobile Codebases: Modernization

    Slack Engineering mediumAdept

    Slack's year-and-a-half Duplo initiative concluded by modernizing its iOS and Android codebases: iOS moved to a custom VIPER-style feature architecture, stricter SwiftLint rules banning singletons and NotificationCenter, Combine (via CombineX until iOS 12 was dropped), and broader SlackKit adoption, while Android replaced Gson with Moshi, Android Priority Job Queue with WorkManager, and handwritten API calls with an internal Retrofit-based library, and introduced coroutines and Compose incrementally. iOS ended 68% modernized and 81% modularized with CI stability rising from 77% to 90% and average time-to-merge down 64%, Android reached 92% modularization, and local builds later dropped nearly 50% with Bazel and M1 Macs. Follow-up work includes layered module dependency rules to stop circular dependencies, possibly adopting Needle for dependency injection, and splitting Android modules into API/implementation pairs for build parallelism.

  • How we use Kotlin for backend services at Zalando

    Zalando Engineering easyNovice

    Zalando moved Kotlin from TRIAL to ADOPT on its Tech Radar, making it the third supported JVM language alongside Java and Scala after 100+ new Kotlin applications were written in a year. A Kotlin Guild with 250+ members produced guidelines, templates and default tooling recommendations for backend services. These defaults include Spring Boot (with Ktor as a rising option), Gradle with Kotlin build scripts, ktlint, kotlin-logging, Lettuce for Redis, JPA or jOOQ for relational databases, and opentracing-toolbox. APIs are defined in OpenAPI and linted with Zally, and auth is handled at the Skipper ingress rather than with Spring Security.

  • 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.

The quest for software engineering knowledge.

Look:
Layout: