我尝试在我的应用程序中实现导航功能。当我尝试构建应用程序时,输出是这样的:
Android resource linking failed
/home/mateusz/AndroidStudioProjects/TakeAndTie/app/src/main/res/layout/activity_main.xml:23: error: attribute defaultNavHost (aka com.mateuszpolito.takeandtie:defaultNavHost) not found.
/home/mateusz/AndroidStudioProjects/TakeAndTie/app/src/main/res/layout/activity_main.xml:23: error: attribute navGraph (aka com.mateuszpolito.takeandtie:navGraph) not found.
error: failed linking file resources.
下面是来自activity_main.xml的nav_host_fragment:
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:defaultNavHost="true"
app:navGraph="@navigation/nav_graph" />
我已经在我的应用级build.gradle中实现了导航:
implementation "androidx.navigation:navigation-ui-ktx:2.1.0-alpha02"
我使用的是Android Studio 3.4版
发布于 2019-09-27 16:39:01
您是否可以添加到项目的build.gradle:
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.2.0-alpha03"
在app/build.gradle中
apply plugin: "androidx.navigation.safeargs.kotlin"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
发布于 2021-11-08 08:26:29
仅将您的activity_main.xml:xmlns:app="http://schemas.android.com/apk/res-auto"
更改为xmlns:app="http://schemas.android.com/apk/res"
https://stackoverflow.com/questions/55974440
复制相似问题