动态功能导航:找不到资源

Dynamic Feature Navigation: Resource not found

我正在使用结合了导航图的动态功能模块。在完成 SplitInstall 过程(动态功能已成功安装)后,我尝试导航到动态功能中的片段,但我始终为包含的导航图获取 ResourceNotFoundException。

应用级导航图:

<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/navigation_app_graph"
    app:startDestination="@id/fragment1">
    <fragment
        android:id="@+id/fragment1"
        android:name="com.test.app.Fragment1"
        android:label="Fragment1"
        tools:layout="@layout/fragment_fragment1">
        <action
            android:id="@+id/action_fragment1_to_fragment2"
            app:destination="@id/navigation_module_two" />
    </fragment>

    <activity
        android:id="@+id/randomActivity"
        android:name="com.test.app.module_two.RandomActivity"
        android:label="RegistrationActivity"
        app:moduleName="module_two" />
    <action
        android:id="@+id/action_global_registrationActivity"
        app:destination="@id/randomActivity" />

    <include-dynamic
        android:id="@+id/navigation_module_two"
        app:graphPackage="com.test.app.module_two"
        app:graphResName="navigation_module_two"
        app:moduleName="module_two"
        tools:layout="@layout/fragment_fragment2">

        <argument
            android:name="aStringParam"
            android:defaultValue=""
            app:argType="string" />
    </include-dynamic>
</navigation>

这里是navigation_module_two:

<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"
    app:startDestination="@id/fragmentTwo"
    tools:ignore="UnusedNavigation">

    <fragment
        android:id="@+id/fragmentTwo"
        android:name="com.test.app.module_two.Fragment2"
        android:label="Fragment2"
        tools:layout="@layout/fragment_fragment2">

        <argument
            android:name="aStringParam"
            android:defaultValue=""
            app:argType="string" />
    </fragment>
</navigation>

奇怪的是:我可以很好地导航到 RandomActivity,因为它没有引用任何资源(没有关联的 XML 布局)。问题特别是当我尝试导航到 Fragment2 时,因为它确实有布局。

这是完整的堆栈跟踪:

2020-11-19 06:43:55.303 20550-20550/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.test.app, PID: 20550
android.content.res.Resources$NotFoundException: com.test.app.module_two:navigation/navigation_module_two
    at androidx.navigation.dynamicfeatures.DynamicIncludeGraphNavigator.replaceWithIncludedNav(DynamicIncludeGraphNavigator.kt:95)
    at androidx.navigation.dynamicfeatures.DynamicIncludeGraphNavigator.navigate(DynamicIncludeGraphNavigator.kt:79)
    at androidx.navigation.dynamicfeatures.DynamicIncludeGraphNavigator.navigate(DynamicIncludeGraphNavigator.kt:40)
    at androidx.navigation.NavController.navigate(NavController.java:1049)
    at androidx.navigation.NavController.navigate(NavController.java:935)
    at androidx.navigation.NavController.navigate(NavController.java:868)
    at androidx.navigation.NavController.navigate(NavController.java:854)
    at androidx.navigation.NavController.navigate(NavController.java:1107)
    at com.test.app.Fragment1$myHandlersListener.moveToNextFragment(Fragment1.kt:219)
    at com.test.app.databinding.NavigationDrawerBindingImpl._internalCallbackOnClick(NavigationDrawerBindingImpl.java:224)
    at com.test.app.generated.callback.OnClickListener.onClick(OnClickListener.java:11)
    at android.view.View.performClick(View.java:7869)
    at android.view.View.performClickInternal(View.java:7838)
    at android.view.View.access00(View.java:886)
    at android.view.View$PerformClick.run(View.java:29362)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:237)
    at android.app.ActivityThread.main(ActivityThread.java:8125)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)

有什么想法吗?

更新 1:

我应该提一下,如果我构建一个通用 APK(而不是一个应用程序包),它就可以正常工作。

最终的解决方案是将 navigation_module_two 的内容放在 navigation_app_graph 中,而不是使用 <include-dynamic>.