Android 动态功能模块导航异常:包含的<;导航>';s id与目标id不同

Android 动态功能模块导航异常:包含的<;导航>';s id与目标id不同,android,android-architecture-navigation,dynamic-feature-module,Android,Android Architecture Navigation,Dynamic Feature Module,我有一个应用程序和一个动态功能模块,我希望从中导航 应用导航图 <?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"

我有一个应用程序和一个动态功能模块,我希望从中导航

应用导航图

<?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.
java.lang.IllegalStateException:包含的id com.xyz.dashboard:id/nav_graph_仪表板与目标id com.xyz:id/nav_graph_仪表板不同。删除id或使其匹配。

从功能导航中删除id似乎可以解决这个问题,但我找不到如何使它们匹配,即使
具有相同的id
android:id=“@+id/nav\u图形\u仪表板”
在本例中,我不需要
的id,但我想知道当
有一个id时,是否有可能从功能导航图中的id中删除
+

android:id="@id/nav_graph_dashboard"

当您使用
@+id
语法时,您将在动态功能的包中创建一个新的id(您将注意到,正是由于这个原因,异常会显式地调用每个资源id的包名称)。通过删除
+
,您可以使用主模块包中已创建的ID,从而使它们匹配。

从功能导航图中的ID中删除
+

android:id="@id/nav_graph_dashboard"

当您使用
@+id
语法时,您将在动态功能的包中创建一个新的id(您将注意到,正是由于这个原因,异常会显式地调用每个资源id的包名称)。通过删除
+
,您可以使用主模块包中已创建的ID,从而使它们匹配。

可以简单地实现相同的非法状态异常,但在根模块的根导航图中包括app:moduleName=“app”(通常为
app
module)。注意确保仅在动态功能模块导航图中设置属性。

可以简单地实现相同的非法状态异常,但在根模块的根导航图中包括app:moduleName=“app”(通常为
app
module)。注意确保仅在动态功能模块导航图中设置属性。

看来,跨包含动态和动态功能模块导航图的导航标记匹配的ID并不重要-这不是用于建立连接的机制,而是graphResName。graphResName应该是动态功能模块导航图的文件名。当处理多个动态功能模块导航图中目标片段的多次使用时,以及如果定义目标片段(使用appModule attr),上述内容将非常清楚在根导航图中,并使用该标记的id进行导航:然后,目标导航图的分辨率取决于graphResName。看来,在整个导航图中匹配的id包括动态和动态功能模块导航图的导航标记并不重要-这不是用于建立连接的机制,而是graphResName。graphResName应该是动态功能模块导航图的文件名。当处理多个动态功能模块导航图中目标片段的多个使用时,上述内容将非常清楚……如果在根导航图中定义目标片段(使用appModule attr)并使用该标记的id进行导航,则目标导航图的分辨率将取决于graphResName。