Modularizing an Android app means splitting one Gradle module into smaller ones, each with a clear job and a clear rule about what it may depend on. A layout that holds up well is a thin :app module, one :feature:* module per product area, shared :core:* libraries, and data modules that own repositories and data sources.
The module graph is not something you draw once at the start. Every new implementation(project(...)) line changes it, so it has to be watched in code review like any other code. In this post I go through the boundaries that matter, which way the arrows should point, how Hilt and navigation work across modules, and the mistakes that slowly turn a modular project back into a monolith.
In short
:appwires things together,:feature:*modules are vertical product slices,:core:*modules are horizontal shared libraries, and data modules own repositories.- Dependencies point one way. Feature modules don't depend on each other's implementations; if they need to talk, they go through a small
:apimodule or through:app. implementationis the default;apiis only for types that appear in your module's public signatures.- Convention plugins in a
build-logicincluded build keep module build files short and consistent. - The common failures are a catch-all
:coremodule, cycles, and data-layer models leaking into the UI. Splitting too early or too finely is a failure too.
What modularization gets you
The first benefit is build time, with some caveats. Gradle skips tasks whose inputs haven't changed, so in a modular project a change in :feature:settings recompiles that module and whatever depends on it, while the other feature modules stay up to date. If the change doesn't touch the module's public ABI, Gradle and the Kotlin compiler can often avoid recompiling the dependents or keep it incremental. Independent modules can also be built in parallel, but only if parallel execution is enabled. Dex merging and packaging in :app still run after every change, so the gain shows up mostly in compilation. How much you save depends on the project; measure it with a build scan or --profile before and after.
The second benefit is ownership. Two developers working on :feature:checkout and :feature:search collide less often, and a reviewer can judge a change by the module it touches and that module's public surface. It's the same idea I used when I separated reading, verification and integration in an eID SDK: you should be able to change what's behind a boundary without the callers noticing.
What modules don't give you is good design. You can draw clean module lines and still write tangled code inside them.
The module map
Google's modularization guide describes app, feature, data, common (core) and test modules. The Now in Android sample follows the same split, and it's a good reference when you are unsure where something belongs.
:app wires everything together
The app module depends on the feature modules, hosts the root NavHost and is where the Hilt component is generated (@HiltAndroidApp). It should contain very little business logic. If you ship several form factors, each one gets its own app module (for example :app and :wear) so platform-specific dependencies stay separate.
// settings.gradle.kts
pluginManagement {
includeBuild("build-logic")
}
include(":app")
include(":core:designsystem")
include(":core:domain")
include(":core:data")
include(":core:model")
include(":core:network")
include(":core:testing")
include(":feature:articles")
include(":feature:bookmarks")
:feature modules are vertical slices
A feature module holds the screens, ViewModels, UI state and navigation entry points of one product area. A feature is not necessarily one screen: a checkout flow with a cart, an address step and a confirmation screen can live in one module, because those screens change together.
A feature module should not depend on another feature module's implementation. Once :feature:checkout imports a class from :feature:search, two parts of the app that should change independently are coupled, and cycles are one step away. If two features really need the same code, that code isn't a feature; it belongs in a core module. If they need to navigate to each other, see the navigation section below.
:core modules are horizontal and shared
Core modules hold code that many features reuse: the design system, networking, common utilities, analytics. A :core:designsystem module owns the theme, typography and shared composables so every feature looks like the same app. Shared UI helpers belong here too, like the reusable back-handling extension I wrote about in moving to OnBackPressedDispatcher.
Core modules can depend on other core modules, but never on a feature or on :app.
Data modules own the repositories
A data module wraps everything about one area of data: the repository, remote and local data sources, and the network and database models. Callers ask the repository for data and don't know whether it came from Retrofit, Room or an in-memory cache. That is what lets you add a cache or change a serialization format without touching any feature.
Dependency direction
The rule fits in one diagram:
:app ──▶ :feature:* ──▶ :core:*
│ ▲
└──────▶ data modules ────┘
feature ──▶ another feature's implementation : not allowed
core / data ──▶ feature or :app : not allowed
:app sees the features; features see core; data modules see core; nothing points back up. When this holds, the graph has no cycles, independent modules can build in parallel, and you can reason about any module on its own.
Gradle only enforces part of this. It fails the build on a cycle, but it will happily let :feature:checkout depend on :feature:search. If you want that rule enforced, add a check to your convention plugin or use a dependency analysis plugin in CI.
What Gradle does give you is control over visibility, through api and implementation. An implementation dependency is used to compile your module but doesn't end up on the compile classpath of modules that depend on you. An api dependency does, so consumers compile against it too.
// core/network/build.gradle.kts
dependencies {
// Types from :core:model appear in this module's public functions,
// so consumers need them on their compile classpath -> api.
api(project(":core:model"))
// Retrofit and OkHttp are internal plumbing. Keep them off
// every consumer's compile classpath -> implementation.
implementation(libs.retrofit)
implementation(libs.okhttp)
}
Use api only when a type really appears in your module's public API. Using it by reflex brings back the old compile configuration, where everything leaked everywhere; Gradle deprecated compile for that reason and has since removed it. implementation also helps build times: a change to an implementation dependency doesn't force consumers of your module to recompile.
Where Clean Architecture layers go
Google's architecture guide talks about a UI layer, a data layer and an optional domain layer in between. In that model, and in Now in Android, the domain layer depends on the data layer: use cases call repositories, and repositories are classes in the data layer.
Clean Architecture takes a different view: dependencies point inward, toward the domain. The domain defines the repository interfaces and the data layer implements them, so at the Gradle level data depends on domain, not the other way around. Both work. I prefer the inverted version in larger codebases because the domain module stays free of Android and of persistence code, and features never see the data implementations. The rest of this post uses that version:
- Presentation lives in
:feature:*: ViewModels, UI state, composables. - Domain is a Kotlin/JVM module,
:core:domain, with no Android dependency. It holds use cases, domain models and the repository interfaces. - Data lives in
:core:data(or:data:*modules) and holds the repository implementations and data sources.
// :core:domain — plain Kotlin. No Android, no Retrofit, no Room.
data class Article(
val id: String,
val title: String,
val publishedAt: Instant,
)
interface ArticleRepository {
fun observeArticles(): Flow<List<Article>>
suspend fun refresh()
}
// :core:data — depends on :core:domain and implements its contract.
internal class DefaultArticleRepository @Inject constructor(
private val remote: ArticleRemoteDataSource,
private val local: ArticleDao,
) : ArticleRepository {
override fun observeArticles(): Flow<List<Article>> =
local.observeAll().map { entities -> entities.map(ArticleEntity::toDomain) }
override suspend fun refresh() {
val network = remote.fetchArticles()
local.upsert(network.map(NetworkArticle::toEntity))
}
}
The ViewModel in :feature:articles depends only on the ArticleRepository interface. It doesn't know Retrofit or Room exist, so it can be tested with a fake repository. I went into why use cases work well as plain suspend functions, with scope and dispatcher handling kept in the upper layers, in my post on moving from RxJava to Kotlin Coroutines.
// :feature:articles — presentation layer, sees only the domain contract.
@HiltViewModel
class ArticlesViewModel @Inject constructor(
repository: ArticleRepository,
) : ViewModel() {
val uiState: StateFlow<ArticlesUiState> =
repository.observeArticles()
.map { articles -> ArticlesUiState.Success(articles.map(Article::toUiModel)) }
.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5_000),
initialValue = ArticlesUiState.Loading,
)
}
Hilt across modules
The code above doesn't compile into a working app yet: Hilt has no way to know which class to provide for ArticleRepository. The binding lives next to the implementation, in :core:data. The implementation class stays internal, and so does the binding function:
// :core:data
@Module
@InstallIn(SingletonComponent::class)
abstract class DataModule {
@Binds
internal abstract fun bindArticleRepository(
repository: DefaultArticleRepository,
): ArticleRepository
}
Hilt builds the component in :app, so :app has to see :core:data. In this layout :app is the only module that depends on it directly:
// app/build.gradle.kts
dependencies {
implementation(project(":feature:articles"))
implementation(project(":feature:bookmarks"))
// The only module that sees the data implementations,
// so Hilt can find their @Binds modules.
implementation(project(":core:data"))
}
The Hilt Gradle plugin's aggregating task, which is on by default in current versions, lets the component see @InstallIn modules that arrive through transitive implementation dependencies too. You don't need to turn dependencies into api just so Hilt can find them.
Navigation between features
If features can't depend on each other, how does the bookmarks screen open an article? The simplest answer is to let :app do it. Each feature exposes its destination as an extension on NavGraphBuilder and takes navigation callbacks as parameters:
// :feature:bookmarks
fun NavGraphBuilder.bookmarksScreen(
onArticleClick: (articleId: String) -> Unit,
) {
composable<BookmarksRoute> {
BookmarksScreen(onArticleClick = onArticleClick)
}
}
:app sees every feature, so it connects them in the NavHost:
// :app
NavHost(navController = navController, startDestination = ArticlesRoute) {
articlesScreen(onArticleClick = navController::navigateToArticle)
articleDetailScreen()
bookmarksScreen(onArticleClick = navController::navigateToArticle)
}
When features need to reference each other's destinations directly, split each of them into a small :feature:x:api module and a :feature:x:impl module. The :api module holds only the route type and maybe a navigateTo... extension; the :impl module holds the screens. :feature:bookmarks:impl can depend on :feature:articles:api, but never on :feature:articles:impl. The modularization guide describes the same idea under dependency inversion: depend on a small abstraction module, not on the implementation.
// :feature:articles:api — no screens, no ViewModels.
@Serializable
data class ArticleDetailRoute(val articleId: String)
fun NavController.navigateToArticle(articleId: String) {
navigate(ArticleDetailRoute(articleId))
}
I wouldn't split every feature into api and impl from day one. Add the split when a second feature actually needs to point at the first one.
Convention plugins and version catalogs
Ten modules mean ten build.gradle.kts files, and without some discipline they drift: one sets a different compileSdk, another forgets the Compose compiler plugin. Convention plugins solve this by putting shared configuration in one place.
Gradle lets you share build logic through buildSrc or through an included build. Now in Android uses an included build called build-logic with small, single-purpose plugins that a module combines as needed. Keep in mind that either way, a change to a convention plugin changes the build classpath of every project that applies it, so those projects are reconfigured and many of their tasks can rerun. Keep the plugins small and change them deliberately.
Dependency versions belong in a version catalog (gradle/libs.versions.toml). Build scripts get a type-safe libs accessor; inside a convention plugin that accessor isn't generated, so you read the catalog by name:
// build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt
class AndroidFeatureConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
pluginManager.apply("myapp.android.library")
pluginManager.apply("myapp.android.compose")
pluginManager.apply("myapp.hilt")
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
dependencies {
add("implementation", project(":core:designsystem"))
add("implementation", project(":core:domain"))
add("implementation", libs.findLibrary("androidx.lifecycle.viewmodel.compose").get())
add("testImplementation", project(":core:testing"))
}
}
}
}
The feature module's build file then contains only what is really specific to it:
// feature/articles/build.gradle.kts
plugins {
id("myapp.android.feature")
}
android {
namespace = "com.example.feature.articles"
}
Every feature module now gets the same SDK levels, Compose setup and baseline dependencies, and you change them in one file. Logic that only one module needs still goes in that module's build file, not into a shared plugin.
As the module count grows, configuration and build times grow with it. These three settings in gradle.properties are worth turning on and checking against your plugins:
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.configuration-cache=true
Parallel execution lets independent modules build at the same time, the build cache reuses task outputs across builds and branches, and the configuration cache skips the configuration phase when nothing in the build setup has changed. Some third-party plugins are not compatible with the configuration cache yet; Gradle reports those problems, so turn it on and fix what it flags.
Testing seams
Module boundaries also make good test seams. Because the ViewModel depends on an interface from :core:domain, a unit test can pass a fake repository without Hilt and without a device or emulator. Shared fakes and test helpers, like a test dispatcher rule or FakeArticleRepository, can live in a :core:testing module that only test source sets depend on. Now in Android does the same.
For instrumented tests that run with Hilt, you can replace the whole data binding with @TestInstallIn:
@Module
@TestInstallIn(
components = [SingletonComponent::class],
replaces = [DataModule::class],
)
abstract class FakeDataModule {
@Binds
abstract fun bindArticleRepository(
repository: FakeArticleRepository,
): ArticleRepository
}
This is also why DataModule itself is public in the previous section: replaces has to reference it from another module.
Common mistakes
The catch-all :core module
A single :core (or :common, or :utils) module starts as a convenient place to put shared code and grows until every module depends on it. Then a change to one unrelated helper recompiles most of the app, and the build-time benefit is gone. Split core along real responsibilities, like :core:designsystem, :core:network, :core:model and :core:common, and split again when a module starts collecting unrelated code.
Cyclic dependencies
A depends on B and B depends on A, directly or through a chain. Gradle refuses to build this, which is the good part. The fix is usually a design change, not a build-file edit, because a cycle means a boundary is in the wrong place. Move the shared piece into a module both can depend on, or invert one dependency with an interface, as in the domain/data split above.
Data models leaking into the UI
A @Serializable network DTO or a Room @Entity is right there, so it gets passed up to the ViewModel and into a composable. Now the UI depends on the wire format: rename a JSON field and a screen breaks. Each layer should have models shaped for its own job, mapped at the boundary.
// :feature:articles — a UI model, separate from the data layer's types.
data class ArticleUiModel(
val id: String,
val title: String,
val relativeTime: String,
)
internal fun Article.toUiModel(): ArticleUiModel =
ArticleUiModel(
id = id,
title = title,
relativeTime = publishedAt.toRelativeTime(),
)
These mappers feel like boilerplate until the API changes and the fix stays in one file.
Modularizing too early or too finely
Every module has a cost: its own build file, its own configuration time, and for Android library modules extra work like manifest merging and resource processing. A small app with one or two developers often doesn't need more than :app plus a few core modules. Splitting into dozens of tiny modules before the boundaries are clear just means moving code between modules later. The modularization guide warns about this too: modules that are too fine-grained add overhead, and modules that are too coarse give you a monolith with a different name. Where a module has no Android dependencies, like :core:domain or :core:model, make it a plain Kotlin/JVM module; it's cheaper to build and test.
Where to start
If you're looking at a single-module app, don't try to split it into twenty modules in one go. Start with modules that many places use and that don't depend on app code, like :core:designsystem and :core:model. Then move one well-understood feature into its own module and see which dependencies it actually needs. Add convention plugins once two or three modules repeat the same build configuration.
After that, the most useful habit is reviewing module dependencies like code. A wrong arrow is cheap to fix in the pull request that adds it and expensive once other modules start relying on it.