导航 Lint 错误:未从任何布局文件中引用此导航图

lui*_*tes 5 android android-navigation android-architecture-navigation android-navigation-editor

我的应用程序中有 2 个模块(应用程序模块和启动模块)。我正在尝试利用<include>标签来使FTUE自包含,而不是文档建议的主导航图的一部分。

我的主导航图在 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/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>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

最后,这是导航图与应用模块中的 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>
Run Code Online (Sandbox Code Playgroud)

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

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 错误所说的真的(我没有另一个NavHostFragmentapp:navGraph="@navigation/splash_nav_graph"),但是:

  • 我将它包含在另一个图形中并且它正在工作(认为这在某种程度上是可传递的,而 lint 无法检测到)
  • 我不知道在哪里添加另一个,NavHostFragment因为我在应用程序模块中只有一个活动。

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

lui*_*tes 4

看起来这个问题将在AS 3.6中修复

  • 我使用的是Android Studio 4.0。Beta 5 仍然没有修复。 (2认同)
  • 我使用 Android Studio 4.0.1,但它仍然没有修复。 (2认同)