A Little Thing about Android Module Paths
How to configure your module paths, instead of using Gradle’s default.
Working to make our Android application more modular, I ended up with a sample that included a set of on-demand features grouped inside a folder:
Pretty standard setup, all the on-demand modules, inside a “features” folder; clean.
These modules are included in the settings.gradle file as:
These setup works nicely with a single “minor” issue: an empty module named
features in the Android view in Android Studio:
I can live with that, but I would much prefer to remove that empty module from my project!
If you cannot remove it, just rename it!
At I/O I was lucky enough to attend the “Android Studio: Tips and Tricks” talk where Ivan Gravilovic, from Google, shared some amazing tips. One of these was a possible solution for my problem: setting a custom path for my modules.
In this particular case our
include ':module4'// Set a custom path for the four features modules.
// This avoid to have an empty "features" module in Android Studio.
project(":module1").projectDir=new File(rootDir, "features/module1")
project(":module2").projectDir=new File(rootDir, "features/module2")
project(":module3").projectDir=new File(rootDir, "features/module3")
project(":module4").projectDir=new File(rootDir, "features/module4")
And the layout in Android Studio is now:
As the title says, this is really a small thing, but it helps keep my project in order and it shows how a small Gradle configuration can help keep your project tidy.
You can find this update in the latest version of the on-demand modules codelab.