Safeargs library doesnt generate direction class

I forgot to apply plugin in app.gradle file, just add this line

apply plugin: "androidx.navigation.safeargs.kotlin"

or this line if you are using java

apply plugin: "androidx.navigation.safeargs"

Look for the class of the fragment which is the source of navigation. If you define navigation from FragmentA to FragmentB, you will find FragmentADirections class with the actions you defined (in nav_graph.xml) in it.

Then, to generate direction class ( Also argument class) you need to go Project level gradle then click the build command. Here I attached a screenshot to give a clear understanding.

enter image description here


I faced a similar issue working with android studio 4.2 preview.

The issue was that the IDE somehow was not picking the source folders where the generated direction classes where being placed by the plugin. So adding the following to my app build.gradle file resolved the issue for me.

sourceSets {
    main {
        java {
            srcDirs += 'build/generated/source/navigation-args'
        }
    }
}

Hope this helps!