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?
The problem seems to be with the
include
s that are missing theapp:graph
attribute. It should be:and so on. Reference.