Navigation Component in a multi-module project or dancing on the rake without being harmed

Anton Uryvskii
2 min readJan 20, 2021

Jetpack Navigation Component is a relatively new tool for building navigation inside an Android application. Google released this library in March 2019 to show a new approach for implementing navigation, different from libraries like Cicerone, Conductor, etc. or custom / self-written methods.

Advantages of the Navigation Component:

  • The product is from Google, which means you can count on long-term support and refinement.
  • It is easy to learn and use.
  • Safe Args plugin which makes working with the library even easier.
  • An embedded in Android Studio editor with visual navigation representation.
  • All the main navigation elements are specified in xml which allows to separate the navigation and the rest of the code from each other.

But there are some nuances. As soon as it comes to navigating a multi-module project with ten or more screens, it turns out that things are not so simple. There is no consistent approach or recommendations in working with the library with such kind of architecture. So I made my own decomposition, organization, and set of rules on working with NavComponent. In addition, the Safe Args plugin, or rather its file generation which did not fit the proposed flow of work, threw a spanner in the works.. Spoiler: as a result, this approach is already used in the 4th project in a row without any complaints.

But let’s get things straight. With this series of stories I will try to give a full understanding of this library. So let’s start with the basics.

  1. We will look at what the Navigation Component is.
  2. Learn how the Safe Args plugin works and what it does.
  3. Next the most interesting part: my approach to working with Navigation Component in a multi-module project with Sage Args.

And a nice bonus-a solution for creating iOS-like multistack navigation.

--

--