Geek Culture
Published in

Geek Culture

Android — Clean Architecture With Dynamic-Features and Hilt/Dagger2 (Pt.2)

Bologna — Italy (2019)


In our previous article we setup our Gradle file and now we are going to start working on our Navigation. If you haven’t checked yet, take a look at the first part of this series.


Our navigation file is going to include our dynamic features and here we must focus on few details otherwise, you’re going to face some issues (Trust me, I had so many issues with that).


As you can see, by adding the dynamic navigation library we have access to the “include-dynamic” object, which requires some parameters to make it work, you may take a look at those parameters on Google’s documentation page, but a good hint for you is that you can use the “${applicationId}” to avoid mistyping the path otherwise, you must define it as:


Inside our feature module, we must define our navigation file, and here’s one of the most important details, the id defined on our “nav_pools” must be the same created on the “nav_home”. In other words, DO NOT add the plus sign here:

<navigation xmlns:android=""
android:id="@id/nav_pools" <--- DO NOT ADD PLUS SIGN HERE

If you add the plus sign here you are going to declare a new id for the navigation file and it won’t match, and the result is this one:

2021-03-04 18:21:27.913 22314-22314/com.okawa.blockchain.mkt E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.okawa.blockchain.mkt, PID: 22314
java.lang.IllegalStateException: The included <navigation>'s id com.okawa.blockchain.mkt.pools:id/nav_pools is different from the destination id com.okawa.blockchain.mkt:id/nav_pools. Either remove the <navigation> id or make them match.

Now we must connect our features and in order to do so, we are going to use the bottom navigation view, first define the menu that is going to be used.


The ids must also match here, the app will not crash if it doesn’t, but the navigation won’t take any action, as you can see in the next animation.

Non-matching ids error

Now we add the menu to our activity file and programmatically setup the bottom navigation menu using the setupWithNavController function.


Voilá!! 🎉
We now have the dynamic navigation working and for this post that’s all.
In our next article, we are going to setup Hilt and Dagger to use the dependency injection.

Any thoughts ideas or suggestions, please add some comments.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store