Android Navigation Component: Fragments are not visible in drop down list when adding destination from nav_graph.xml
Asked Answered
J

6

9

When I am trying to add a destination when clicking enter image description here "New destination" button, from the dropdown list I am not able to see any fragments which are already there in my project.

I also face this issue when I am trying to add a blank fragment by clicking "Create a blank destination" option from the drop down.

I tried restarting the IDE, and this Android Navigation Component Not Displaying Fragment but it doesn't resolve my issue.

Navigation dependency: implementation "androidx.navigation:navigation-fragment:1.0.0-rc02"

My project is already migrated to AndroidX.

Am I missing something? Any help would be appreciated.

Gradle dependency:

def nav_version = "1.0.0-rc02"

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.2-alpha02'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha02'
implementation 'androidx.cardview:cardview:1.0.0'

implementation "android.arch.navigation:navigation-fragment:$nav_version"
Johnajohnath answered 12/3, 2019 at 4:31 Comment(6)
try rebuild the project.Parmenter
Sounds like you should file an issue against the Navigation Editor with a project that reproduces your issue.Equivalence
Can you share your gradle with the dependency list?Handmedown
@MDNaseemAshraf edited the question.Johnajohnath
I think I am using wrong dependencyJohnajohnath
Thank you everyone for your help, I created a new fresh android project to check if the problem is related to IDE or not. Able to create destinations.Johnajohnath
P
7

I had the same problem. Just use these dependencies.

//Android Navigation Architecture
    implementation "androidx.navigation:navigation-fragment-ktx:2.1.0-alpha05"
    implementation "androidx.navigation:navigation-ui-ktx:2.1.0-alpha05"
Paraph answered 23/8, 2019 at 0:24 Comment(1)
adding the navigation-fragment dependency did the trick for me!Gaulish
G
1

I had the same problem and i solved it by simply checking the superior build-gradle for the kotlin version, it may be the case if you recently updated your kotlin plugin but didnt update your code.

So in android studio in project navigation bar(ANDROID): Gradle Scripts -> build.gradle(project) -> look for buildscript - ext and update "kotlin_version" for your kotlin plugin version (this can be checked in tools -> kotlin -> Configure kotlin plugin updates)

Gloss answered 3/1, 2022 at 17:9 Comment(0)
E
0

I also had the exact same problem, I was using older library version(1.0.0-alpha05)

But as soon as I switched to

implementation "android.arch.navigation:navigation-fragment-ktx:1.0.0"
implementation "android.arch.navigation:navigation-ui-ktx:1.0.0"

Other fragments started showing up!

Enuresis answered 13/12, 2019 at 10:18 Comment(0)
S
0

I am facing this issue even with version 2.2.1. I have solved this by adding the fragment in the XML code. Then I am able to add actions from the visual editor.

Example:

<fragment
    android:id="@+id/test"
    android:name="com.example.test.ui.test.TestFragment"
    android:label="Test Label"
    tools:layout="@layout/fragment_test"/>
Spiderwort answered 16/3, 2020 at 9:33 Comment(0)
P
0

Sometimes Fragments don't show up in the graph because classes haven't been made for them. After calling onViewCreate within a class, while returning correct inflater they show up in the graph.

Pershing answered 12/9, 2020 at 11:50 Comment(0)
L
0

Just I built and Run the project once. Then Fragments appeared as destinations in the Fragments List in NavGraph.

Layout answered 28/7, 2021 at 14:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.