Failed to resolve: fragment after adding navigation

Viewed 2403

I got this error when I try to add dependencies for Navigation

Failed to resolve: fragment

I have add those lines:

implementation "android.arch.navigation:navigation-fragment-ktx:$navigationVersion"
implementation "android.arch.navigation:navigation-ui-ktx:$navigationVersion"

In project gradle this is what I add:

ext{
    navigationVersion = '1.0.0-alpha09'
}
repositories {
    google()
    jcenter()
}

I tried to invalidate cache & restart and It didn't work.

Side note I have migrated to androidx with no problem but after I tried to add the Navigation library, this error appears

4 Answers

I found the same problem when trying to use the code that i found on the Udacity lecture.

implementation "android.arch.navigation:navigation-fragment-ktx:$navigationVersion"
implementation "android.arch.navigation:navigation-ui-ktx:$navigationVersion"

The problem is that I am using the AndroidX, I need to change the the group name of these dependencies from android.arch.navigation into androidx.navigation

implementation "androidx.navigation:navigation-fragment-ktx:$navigationVersion"
implementation "androidx.navigation:navigation-ui-ktx:$navigationVersion"

detail information describes here: https://developer.android.com/kotlin/ktx

In your code, set navigationVersion = '2.0.0' is OK

I was getting this problem too, I had connection problems and it could not download the dependencies.

  • Cleaned project
  • Solved connection problems
  • Restarted android studio

and now all is fine.

Related