Android 导航Lint错误:此导航图未从任何布局文件中引用
我的应用程序中有2个模块(应用程序模块和飞溅模块)。我正试图利用Android 导航Lint错误:此导航图未从任何布局文件中引用,android,android-navigation,android-architecture-navigation,android-navigation-editor,Android,Android Navigation,Android Architecture Navigation,Android Navigation Editor,我的应用程序中有2个模块(应用程序模块和飞溅模块)。我正试图利用标记,使其成为自包含的,而不是像文档所建议的那样成为主导航图的一部分 我的主导航图在应用程序模块中定义,如下所示: <?xml version="1.0" encoding="utf-8"?> <navigation xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com
标记,使其成为自包含的,而不是像文档所建议的那样成为主导航图的一部分
我的主导航图在应用程序模块中定义,如下所示:
<?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>
最后,这里是主导航图与应用程序模块中的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-in->home)产生预期的行为。但是,splash\u nav\u图形的顶部出现以下lint错误:
此导航图未从任何布局文件中引用(应至少在一个布局文件中找到它,其中包含一个带有app:navGraph=“@navigation/splash_nav_graph”属性的NavHostFragment)。更多(⌘F1)
lint错误所说的是真的(我没有另一个NavHostFragment
有app:navGraph=“@navigation/splash\u nav\u graph”
),但是:
- 我正在将它包含到另一个图表中,它正在工作(认为这是某种可传递的,lint无法检测到)
- 我不知道在哪里添加另一个
NavHostFragment
,因为我在应用程序模块中只有一个活动
我真的需要在某个地方添加另一个NavHostFragment
,还是这是lint中的一个bug?看起来这将在中修复,听起来像是lint中的一个误报,您应该修复。非常感谢您这么快回复。节省了我大量的时间和头发!为有兴趣关注它的人创建了一个问题。我使用Android Studio 4.0。Beta 5版仍然没有修复。我使用的是Android Studio 4.0.1,它仍然没有修复。
<?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>