Ошибка навигационной строки: на эту навигационную диаграмму не ссылаются никакие файлы макета - PullRequest
1 голос
/ 01 июня 2019

В моем приложении 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 определено в модуле заставки (модуль приложения, очевидно, зависит от него):

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

Наконец, вот макет, где основной навигационный граф привязан к 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>

Это будет выполнено, и навигация по потоку (home-> splash -> sign -> home) приведет к ожидаемому поведению. Тем не менее, в верхней части 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 - это true (у меня нет другого NavHostFragment с app:navGraph="@navigation/splash_nav_graph"), однако:

  • Я включаю его в другой график, и он работает (думая, что это как-то транзитивно, и Линт не может это обнаружить)
  • Я понятия не имею, куда добавить еще NavHostFragment, потому что у меня есть только одно действие в модуле приложения.

Мне действительно нужно добавить еще NavHostFragment куда-нибудь или это ошибка в линте?

1 Ответ

0 голосов
/ 14 июня 2019

Похоже, это будет исправлено в AS 3.6

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...