有没有办法使用导航组件在 Android 多模块项目中创建隐式深层链接
Is there a way to create implicit deeplink in Android Multi-module project using Navigation Component
我有一个多模块项目,我需要在其中处理应用内的深层链接。深层链接可以指向任何具有自己的导航图的功能模块。这是一个单一的 - Activity 项目。
我的项目包括功能 1、功能 2 的模块,以及依赖于这两个功能模块的主应用程序模块。这些模块中的每一个都包含自己的导航图以维护自己的流程。我正在尝试创建一个隐式深层链接,如 documentation
中所示
我的应用模块的导航图具有嵌套的功能 1 和 2s 图,如下所示
<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" />
我在导航图中定义了功能一的深层链接 - 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>
在 AndroidManifest 中,我已经指出应该使用具有嵌套图表的主导航
<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>
我希望该项目使用导航组件深入链接到应用程序中的任何模块,但我在编译过程中遇到错误,找不到包含的图表
Referenced navigation file with navigationXmlId = navigation_feature_one not found
这个问题看起来可能是这个错误的表现https://issuetracker.google.com/issues/112513722
问题跟踪器建议将此作为解决方法:
// 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
我有一个多模块项目,我需要在其中处理应用内的深层链接。深层链接可以指向任何具有自己的导航图的功能模块。这是一个单一的 - Activity 项目。
我的项目包括功能 1、功能 2 的模块,以及依赖于这两个功能模块的主应用程序模块。这些模块中的每一个都包含自己的导航图以维护自己的流程。我正在尝试创建一个隐式深层链接,如 documentation
中所示我的应用模块的导航图具有嵌套的功能 1 和 2s 图,如下所示
<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" />
我在导航图中定义了功能一的深层链接 - 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>
在 AndroidManifest 中,我已经指出应该使用具有嵌套图表的主导航
<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>
我希望该项目使用导航组件深入链接到应用程序中的任何模块,但我在编译过程中遇到错误,找不到包含的图表
Referenced navigation file with navigationXmlId = navigation_feature_one not found
这个问题看起来可能是这个错误的表现https://issuetracker.google.com/issues/112513722
问题跟踪器建议将此作为解决方法:
// 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