Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

I have 2 modules in my app (app module and splash module). I'm trying to leverage the <include> tag in an effort to make the FTUE self contained and not a part of the main nav graph as the docs suggest.

My main nav graph is defined in the app module and looks like this:

<?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 is defined in the splash module (app module obviously has a dependency on it):

<?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>

Finally, here's the layout where the main nav graph is tied to the NavHostFragment back in the app module:

<?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>

This will run and navigating through the flow (home-> splash -> sign in -> home) yields the expected behavior. However, the following lint error is present at the top of 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)

What the lint error says is true (I don't have another NavHostFragment that has app:navGraph="@navigation/splash_nav_graph") , however:

  • I am including it into another graph and it's working (thinking there is that this is somehow transitive and lint can't detect that)
  • I have no idea where to add another NavHostFragment because I only have a single activity in the app module.

Do I actually need to add another NavHostFragment somewhere or is this a bug in lint?

like image 538
luis_cortes Avatar asked Jun 01 '19 03:06

luis_cortes


1 Answers

Looks like this will be fixed in AS 3.6

like image 156
luis_cortes Avatar answered Oct 19 '22 07:10

luis_cortes