我有一个应用程序和一个动态功能模块,我希望从中导航
应用导航图
<?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>
具有相同的 ID android:id="@+id/nav_graph_dashboard"
我不需要 <navigation>
的 id对于这个例子,但我想知道 <navigation>
是否有可能有一个
最佳答案
删除 +
从您的功能导航图中的 ID:
android:id="@id/nav_graph_dashboard"
当您使用 @+id
语法,您可以在动态功能的包中创建一个新 ID(您会注意到异常明确地调用每个资源 ID 的包名称正是出于这个原因)。通过删除 +
,您使用主模块包中已创建的 ID,这使它们匹配。
关于android - 动态功能模块导航 IllegalStateException : The included <navigation>'s id is different from the destination id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62704720/