我有一个应用程序和一个动态功能模块,我希望从中导航
应用导航图
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_graph"
app:startDestination="@id/mainFragment">
<!-- Main Fragment from App Module -->
<fragment
android:id="@+id/mainFragment"
android:name="com.xyz.MainFragment"
android:label="MainFragment"
tools:layout="@layout/fragment_main">
<action
android:id="@+id/action_mainFragment_to_nav_graph_home"
app:destination="@id/nav_graph_home" />
</fragment>
<!-- Home Navigation from App Module-->
<include app:graph="@navigation/nav_graph_home" />
<include-dynamic
android:id="@+id/nav_graph_dashboard"
android:name="com.feature.dashboard"
app:graphResName="nav_graph_dashboard"
app:moduleName="dashboard" />
</navigation>
和功能导航
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_graph_dashboard"
app:moduleName="dashboard"
app:startDestination="@id/dashboardFragment1">
<fragment
android:id="@+id/dashboardFragment1"
android:name="com.feature.DashboardFragment1"
android:label="DashboardFragment1">
</fragment>
</navigation>
返回错误
java.lang.IllegalStateException: The included <navigation>'s id com.xyz.dashboard:id/nav_graph_dashboard is different from the destination id com.xyz:id/nav_graph_dashboard. Either remove the <navigation> id or make them match.
似乎从功能导航中删除 id 解决了这个问题,但我找不到如何使它们匹配,即使两者都<include-dynamic>
具有<navigation>
相同的 idandroid:id="@+id/nav_graph_dashboard"
我在这个例子中不需要 id<navigation>
但我想知道何时<navigation>
有一个