Things you should do in case your NavDirections class is not generating properly

Nikolay Miroshnychenko
1 min readDec 20, 2022

--

Photo by Xavi Cabrera on Unsplash

So, recently I’ve been working a lot with the nav components. The most frustrating thing about it that sometimes some of the automatically generated NavDirections class would not generate properly. Just for no reason. I would have an error pop-up saying that a certain fragment could not be found in my navigation graph, but after quadruple-checking everything I was 100% sure that the problem is not my code.

Anyways, StackOverflow didn’t really help either as I would find answers similar to this one. And as one of the people pointed out there the problem looks like a cache one indeed. So here’s the algorithm that worked for me:

  1. Clear and Invalidate cache. File -> Invalidate Caches… -> Tick the “Clear file system cache and Local History” -> Invalidate and Restart
  2. In your app-level build.gradle file in the “plugins” section remove the ’androidx.navigation.safeargs.kotlin’.
  3. Try to build the app after that (it’s going to fail of course)
  4. Then insert the safeargs back again and build the app.

Voila! My stubborn NavDirections class got generated properly.

Let me know in the comments if you have also faced a similar problem and how have you resolved it.

--

--

Nikolay Miroshnychenko
Nikolay Miroshnychenko

Written by Nikolay Miroshnychenko

Android engineer. Learning daily and sharing my knowledge in the process. Into mobile, computer science, and the brain.

Responses (1)