I'm working on a small project and trying to use the new navigation architecture components. When i'm trying to add some arguments to a destination i got "Unresolved reference: NavArgs" error.
I followed this guide https://developer.android.com/topic/libraries/architecture/navigation/navigation-pass-data#kotlin and already added
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha11"
to my project gradle file and also added
apply plugin: 'androidx.navigation.safeargs.kotlin'
to my app gradle file.
As seen in the guide above i want to use val args: AddKittenFragmentArgs by navArgs()
to get the passed arguments. But navArgs()
isn't recognized.
Also NavArgs
in the generated code isn't resolved.
data class MyFragmentArgs(val argOne: String? = "\"\"", val argTwo: String? = "\"\"") : NavArgs
As per the documentation on that very page:
When using the
-ktx
dependencies, Kotlin users can also use the by navArgs() property delegate to access arguments.
Make sure you are following the Adding Components documentation and using the navigation-fragment-ktx
dependency:
implementation "android.arch.navigation:navigation-fragment-ktx:1.0.0-alpha11"
In my case i typed the argument Name starting by a capital letter
<argument
android:name="MyArgument" // changed it to myArgument fix the problem
app:argType="string"
app:nullable="false" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With