JetPack 导航 - <include> 标记中缺少 'graph' 属性
JetPack Navigation - Missing 'graph' attribute in <include> tag
我开始使用导航组件,我的层次结构是:
我有一个名为 nav_graph
的布局并且是:
<?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>
然后我将布局创建为:
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>
但是当 运行 应用
时我收到了这个错误
error: Missing 'graph' attribute in tag.
还有这个
Navigation XML document element must contain a app:graph attribute, whose value begins with @navigation/.
我错过了什么?
问题似乎出在缺少 app:graph
属性的 include
上。应该是:
<include
app:graph="@id/featureHomeNavGraph"
... />
等等。 Reference.
我开始使用导航组件,我的层次结构是:
我有一个名为 nav_graph
的布局并且是:
<?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>
然后我将布局创建为:
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>
但是当 运行 应用
时我收到了这个错误error: Missing 'graph' attribute in tag.
还有这个
Navigation XML document element must contain a app:graph attribute, whose value begins with @navigation/.
我错过了什么?
问题似乎出在缺少 app:graph
属性的 include
上。应该是:
<include
app:graph="@id/featureHomeNavGraph"
... />
等等。 Reference.