I am using safe-args to pass arguments from one fragment to the other. Android studio intermittently generates the fragmentArgs class with all the arguments.
What I have tried, and does work, is altering the nav graph file, making the project, then undo those changes, and finally, make the project again.
Dependencies Used:
Project module:
ext.nav_version = '2.2.0-beta01'
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
App module:
apply plugin: "androidx.navigation.safeargs.kotlin"
<fragment
android:id="@+id/someFragment"
android:name="package_name.SomeFragment"
android:label="@string/some_fragment">
<argument
android:name="source"
android:defaultValue="-1"
app:argType="integer" />
<argument
android:name="nationalId"
android:defaultValue="-1"
app:argType="integer" />
<argument
android:name="hudumaNumber"
android:defaultValue="-1"
app:argType="string" />
<argument
android:name="middleName"
android:defaultValue="None"
app:argType="string" />
</fragment>
I expect that all the arguments will be found in the generated class, but that is not the case.
Try switching to:
apply plugin: "androidx.navigation.safeargs"
instead of:
apply plugin: "androidx.navigation.safeargs.kotlin"
This will generate Java code instead of Kotlin code inside your app\build\generated folder. This doesn't effect your own code and you can continue to use Kotlin or Java for your Fragments.