android - 动态功能模块导航 IllegalStateException : The included <navigation>'s id is different from the destination id

标签 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>
和功能导航
<?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/

相关文章:

Android navArgs 背面清晰

android - Resources$NotFoundException 动态特性模块中的配置更改后

android - 使用内部应用程序共享来测试按需动态功能模块不起作用

java - 如何对用户输入的字符串进行分组

android - 克MM : Unable to generate classes in iOS for the implementation of sealed interfaces inside sub-modules of shared code

android - 不要在 ListView 中停止动画

android - 通过 NavDeepLinkBuilder 的 PendingIntent 发送参数

android - 在导航组件中包含来自 Backstack 的 fragment

android - 带有 Flutter 的动态特征模块

android - android studio中的proguard问题