Navigation Lint Error: This navigation graph is not referenced from any layout files

Navigation Lint Error: This navigation graph is not referenced from any layout files

我的应用程序中有 2 个模块(应用程序模块和启动模块)。我正在尝试利用 <include> 标签来努力使 FTUE 独立,而不是像文档建议的那样成为主导航图的一部分。

我的主导航图在应用模块中定义,如下所示:

<?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/home">

  <include app:graph="@navigation/splash_nav_graph"/>

  <fragment
      android:id="@+id/home"
      android:name="com.example.Home"
      android:label="fragment_home"
      tools:layout="@layout/fragment_home">
    <action
        android:id="@+id/action_home_to_splash_nav_graph"
        app:destination="@id/splash_nav_graph"/>
  </fragment>

</navigation>

splash_nav_graph定义在splash模块中(app模块显然对它有依赖):

<?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/splash_nav_graph"
    app:startDestination="@id/splashFragment">

  <fragment
      android:id="@+id/splashFragment"
      android:name="com.example.splash.SplashFragment"
      android:label="example"
      tools:layout="@layout/fragment_splash">
    <action
        android:id="@+id/action_splashFragment_to_signInFragment"
        app:destination="@id/signInFragment"
        app:enterAnim="@anim/slide_in_right"
        app:exitAnim="@anim/slide_out_left"
        app:popEnterAnim="@anim/slide_in_left"
        app:popExitAnim="@anim/slide_out_right"/>
  </fragment>

  <fragment
      android:id="@+id/signInFragment"
      android:name="com.example.splash.signin.ui.SignInFragment"
      android:label="fragment_sign_in"
      tools:layout="@layout/fragment_sign_in">
    <action
        android:id="@+id/action_signInFragment_pop"
        app:popUpTo="@id/splash_nav_graph"/>
  </fragment>
</navigation>

最后,这是 main 导航图与应用模块中的 NavHostFragment 绑定的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    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/mainContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity"
    >

  <fragment
      android:id="@+id/nav_host_fragment"
      android:name="androidx.navigation.fragment.NavHostFragment"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      app:defaultNavHost="true"
      app:navGraph="@navigation/nav_graph"
      />

</LinearLayout>

这将 运行 并通过流程导航(主页-> 启动画面 -> 登录 -> 主页)产生预期的行为。但是,splash_nav_graph 的顶部存在以下 lint 错误:

This navigation graph is not referenced from any layout files (expected to find it in at least one layout file with a NavHostFragment with app:navGraph="@navigation/splash_nav_graph" attribute). more... (⌘F1)

lint 错误所说的 正确的(我没有另一个具有 app:navGraph="@navigation/splash_nav_graph"NavHostFragment),但是:

我真的需要在某处添加另一个 NavHostFragment 还是这是 lint 中的错误?

看起来这将在 AS 3.6

中修复