I am using a dynamic-feature module combined with a navigation graph. After going through the SplitInstall process (the dynamic feature is successfully installed), I attempt to navigate to a fragment in the dynamic-feature, but I am consistently getting a ResourceNotFoundException for my included navigation graph.
App Level Navigation Graph:
<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>
Here is 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>
Here is the weird thing: I can navigate just fine to RandomActivity
because it does not reference any resources (no associated XML layout). The problem is specifically when I try to navigate to Fragment2
because it does have a layout.
Here is the full stacktrace:
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$1.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.access$3600(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)
Any ideas?
UPDATE 1:
I should mention that if I build a universal APK (instead of an app bundle), this works fine.
The eventual solution was to place the contents of navigation_module_two
inside of navigation_app_graph
instead of using <include-dynamic>
.