narko
narko

Reputation: 3875

Android Studio Navigation editor shows "Ambiguous type" on fragments

I am trying to create a navigation graph using the editor, but unfortunately it is showing "Ambiguous Type" on all my available fragments. I tried creating a new fragment, but still the same problem.

NAC editor

This issue results in the editor not showing the destinations that are available in the XML file.

I have cleaned the AS cache and restarted but this didn't fix anything. I started a new project from scratch and there everything seems to work correctly, so somehow there must be something in my project configuration that affects the navigation editor.

Did anyone experience something similar? Any clue what might be happening?

Upvotes: 3

Views: 502

Answers (3)

Icyrockton
Icyrockton

Reputation: 23

If you have multiple modules , Make sure the version of the imported Fragment is consistent

test

The dependencies above will cause Navigation ambiguous type

solution
In everyModule build.gradle

implementation "androidx.navigation:navigation-fragment-ktx:2.2.2"
implementation 'androidx.navigation:navigation-ui-ktx:2.2.2'

this will override default fragment version 1.1.0 --> 1.2.4

Upvotes: 1

Sarvesh Athawale
Sarvesh Athawale

Reputation: 281

If you are using the modular architecture and the fragment which you have extended is inherits from one of the modules then you should use the navigation fragment dependency with those subsequent modules too.

Upvotes: 0

Sujit Poudel
Sujit Poudel

Reputation: 541

For me, it was because of conflict between two different types of fragment imports. I had this in my build.gradle

implementation "androidx.fragment:fragment:$androidx_fragment_version"
implementation "androidx.navigation:navigation-fragment-ktx:$androidx_navigation_version"
implementation "androidx.navigation:navigation-ui-ktx:$androidx_navigation_version"

Since navigation fragment is being imported through navigation-fragment-ktx, I removed the fragment

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

Hopefully someone finds this helpful as well. I could not find answer anywhere else.

Upvotes: 2

Related Questions