JetPack Navigation - Missing 'graph' attribute in <include> tag

425 views Asked by At

I'm starting to use navigation component and my hierarchy is :

I have a layout named nav_graph and is:

<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/nav_graph"
    app:startDestination="@id/featureHomeNavGraph">

    <include
        android:id="@+id/featureHomeNavGraph"
        app:graphResName="feature_home_nav_graph"
        app:moduleName="feature_home" />

    <include
        android:id="@+id/featureFavouritesNavGraph"
        app:graphResName="feature_favourites_nav_graph"
        app:moduleName="feature_favourites" />

    ...
</navigation>

And then I've created the layouts as :

feature_home_nav_graph.xml

<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:moduleName="feature_home"
    app:startDestination="@id/homeFragment">
    <fragment
        android:id="@+id/homeFragment"
        android:name="HomeFragment"
        android:label="HomeFragment"
        app:moduleName="feature_home" />
</navigation>

feature_favourites_nav_graph.xml

<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:moduleName="feature_favourites"
    app:startDestination="@id/favouritesFragment">
    <fragment
        android:id="@+id/favouritesFragment"
        android:name="FavouritesFragment"
        android:label="FavouritesFragment"
        app:moduleName="feature_favourites" />
</navigation>

But I'm getting this error when running the app

error: Missing 'graph' attribute in tag.

And this one too

Navigation XML document element must contain a app:graph attribute, whose value begins with @navigation/.

What I'm missing?

1

There are 1 answers

2
Onik On BEST ANSWER

The problem seems to be with the includes that are missing the app:graph attribute. It should be:

<include
    app:graph="@id/featureHomeNavGraph"
    ... />

and so on. Reference.