Dynamic inclusion of modules into stand alone android project builds.

siva ramakrishna kv
AndroidUnboxer
Published in
2 min readMar 1, 2020

As a developer we tend to work on multiple projects at some point in your coding life time. As you keep switching between projects you will tend load/unload projects into IDEs like Android Studio and end up maintaining multiple copies of the same code under different projects.

The real pain in running multiple IDEs is

you experience slow system response and confusion navigating between projects which will in a way impact your productivity.

Also in some cases, you may have to work on some common library code which can be used by multiple stand alone android projects to finish your feature development in the application. In such cases, maintaining different copies(by using git sub-module) of the common module is another pain that fuels up.

Luckily, gradle system provides an option to soft link the projects which ever you would like to include as part of the application workspace through

Settings.gradle

Settings.gradle file will be created whenever we create a project in Android Studio. This allows us to add list of modules/projects to be included in the workspace/project’s build.

Ex:

include ‘:projectC’
project(‘:projectC’).projectDir = new File(rootProject.projectDir,‘../projectC/’)

Re-drawing the above picture will yield this.

Option-1

Include the above code in each project.

Option-1

Option-2

Create a sample android studio project MyWorkSpace. Include the below code in MyWorkSpace project’s Settings.gradle.

include ‘:projectA’
project(‘:projectA’).projectDir = new File(rootProject.projectDir,‘../projectA/’)
include ‘:projectB’
project(‘:projectB’).projectDir = new File(rootProject.projectDir,‘../projectB/’)
include ‘:projectC’
project(‘:projectC’).projectDir = new File(rootProject.projectDir,‘../projectC/’)
Option-2

Personally, i like the option-2 here as i simply create a workspace project and keep including different projects in it. This way

I don’t need to switch between multiple IDE windows.

No need to maintain multiple copies of the same code under different projects.

I hope this will be useful if you are already not doing this and please post your learning. If already using this approach please drop in your experience and let me know if any better approach.

Lastly, hit the claps button if you like it otherwise go and kill some mosquito(hehe). Keep yourself high on medium for more articles.

--

--