Core/Core-Impl Pattern: Build-Performance Superpower of DI & Gradle
Article Summary
Your modular Android app is building like a monolith. One shared :core module is killing your build times, even when you change a single private implementation detail.
Pavan Varma breaks down the Core/Core-Impl pattern for Android projects. This architectural approach uses dependency injection to separate interface contracts from heavy implementations, unlocking true parallel compilation in Gradle.
Key Takeaways
- Clean builds dropped from 15 min to 10 min (33% faster)
- Split :core into lightweight interfaces and heavy :core-impl implementation
- Features compile in parallel since they never depend on :core-impl
- Changes to common code no longer trigger feature module recompilation
- Works seamlessly with Hilt for dependency injection
By separating what features need (interfaces) from how it's implemented, teams achieve dramatic build speed improvements without throwing hardware at the problem.
About This Article
Every time :core changed, feature modules had to recompile even if only private implementation details were affected. This happened because all features depended on one shared module that mixed interfaces, implementations, and third-party libraries together.
Pavan Varma's Core/Core-Impl pattern splits the shared module into two parts. :core contains just interfaces and data models with few dependencies. :core-impl holds the heavy implementations like Retrofit and Room. Feature modules only depend on :core through Hilt dependency injection.
Gradle can now compile feature modules and :core-impl in parallel since they don't depend on each other. Compilation avoidance also kicks in because changes to :core-impl don't affect :core's public ABI, so feature modules don't need to recompile unnecessarily.