OLX Sahil Jain Jul 6, 2021

Scaling Android Apps with Gradle: Different Source Sets (Part 2)

M2 Related OWASP risk: Inadequate Supply Chain Security Learn more →

Article Summary

OLX Engineering scaled their Android app across multiple markets without creating code chaos. Here's how they used Gradle source sets to keep things clean.

This is Part 2 of OLX's series on scaling Android apps with Gradle. While Part 1 covered build types and product flavors, this deep dive shows how different source sets let you compile only what each variant needs.

Key Takeaways

Critical Insight

Gradle source sets let you organize code by build variant, compiling only what's needed while maintaining flexibility without maintenance overhead.

The article reveals a clever class diagram pattern that makes flavored dependencies work seamlessly across your entire architecture.

About This Article

Problem

OLX needed to keep debugging libraries like Stetho and LeakCanary out of release builds to reduce size, but include them in debug builds. The challenge was that both build variants needed the same method signatures with different implementations.

Solution

Sahil Jain's team set up separate source directories for debug and release builds. Each contained a LibUtil.kt file with identical method signatures. The debug version initialized the libraries while the release version used empty placeholder methods.

Impact

This eliminated runtime conditionals and build-time property checks. Gradle compiled only the code needed for each variant. The single codebase structure scaled across multiple build types without extra maintenance work.