I have a multi-module project, where I need to handle deep-linking within the app. The deep-links can be to any feature module with it's own navigation graph. This is a Single - Activity project.
My project includes modules for feature 1, feature 2, and main app module that depends on the two feature modules. Each of these modules contain their own navigation graph to maintain their own flows. I am trying to create an implicit deeplink, as seem in the documentation
My app module's navigation graph has nested feature 1 and 2s graphs like below
<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_main"
app:startDestination="@id/start_destination"
tools:ignore="UnusedNavigation">
<include app:graph="@navigation/navigation_feature_one" />
<include app:graph="@navigation/navigation_feature_two" />
I have the deeplink for feature one defined in the navigation graph - navigation_feature_one
<navigation>
...
<fragment android:id="@+id/featureOneFragment"
android:name="com.app.featureone.presentation.SomeFragment"
tools:layout="@layout/some_fragment"
android:label="@string/title_some_fragment">
<deepLink app:uri="www.example.com/featureone"/>
</fragment>
</navigation>
In the AndroidManifest, I have indicated that the main navigation which has nested graphs should be used
<activity
android:name=".presentation.NavigationActivity"
android:launchMode="singleTask"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="www.example.com"/>
<data android:scheme="https"/>
<data android:scheme="http"/>
</intent-filter>
<nav-graph android:value="@navigation/navigation_main" />
</activity>
I am expecting the project to deeplink into any module within the app using navigation component, but I get an error during compilation that the included graphs cannot be found
Referenced navigation file with navigationXmlId = navigation_feature_one not found
This issue looks like it could be a manifestation of this bug https://issuetracker.google.com/issues/112513722
The issue tracker suggests this as a workaround:
// Copy these to the app module's build.gradle
task copyChildNavigationGraphs(type: Copy) {
from '../feature-module/src/main/res/navigation'
into 'src/main/res/navigation'
}
preBuild.dependsOn copyChildNavigationGraphs