动态功能模块导航 IllegalStateException:包含的 <navigation> 的 id 与目标 id 不同

Thr*_*ian 4 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"
    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>
Run Code Online (Sandbox Code Playgroud)

以及功能导航

<?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>
Run Code Online (Sandbox Code Playgroud)

返回错误

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.
Run Code Online (Sandbox Code Playgroud)

似乎从功能导航中删除 id 可以解决问题,但我找不到如何使它们匹配,即使两者都<include-dynamic>具有<navigation>相同的 idandroid:id="@+id/nav_graph_dashboard"我不需要<navigation>此示例的 id 但我想知道是否有可能<navigation>有一个

ian*_*ake 8

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

android:id="@id/nav_graph_dashboard"
Run Code Online (Sandbox Code Playgroud)

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