
Maverick Mambo
Pathfinder @ Thamani
Resources should be central and feature agnosticEvery Android application has resources — images, videos, animation files, you name it. Once you start modularising an application, sharing those resources gets tricky.
The Problem
Every newfeature module comes with its own set of resources.
Sometimes a resource is needed in more than one module, so we duplicate it. Do this enough times and you end up with something like:
Example
project
features
featureA
res
drawable
my_image.png
featureB
res
drawable
my_image.png
Problems
- duplicated resources
- increased application size
- harder to maintain (an update to the image requires you to update it in all modules its used)
Although tempting, AVOID feature interdependency, featureA shouldn’t know about featureB
The Shared resources Module
Create a single module, put all your shared resources inside it, and have every feature module depend on it.
This solves all the problems above.
create a new module
We will introduce a new module called
resourcesapp
features
featureA
featureB
resources (your new module)
Keep this module lean. It shouldn’t need many dependencies
add the resources module into each feature
Add the resources module as a dependency in each feature
build.gradle.kts
If you’re going to repeat this for each module, you could create a convention plugin for it
But there’s always more 😉
The Thamani Way
At Thamani, we think about developer experience the same way we think about user experience — if something feels off, it’s worth fixing. The shared resources module worked, but using it didn’t feel right. The problem was theR class. You’d import it, autocomplete would show you two options, and you’d have to pause
and think: is this R from my feature module or from the shared resources module? That small friction added up
across the codebase.
So we wrapped the shared R class in a helper that makes the source obvious at a glance:
R you’re looking at, you write this:
ThamaniResource.Drawable.my_image, you know exactly where it lives. No second-guessing.
Small details like this are what turn a working codebase into one that’s actually pleasant to work in — and at
Thamani, that matters to us just as much as the experience our users get.