Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android resource linking failed, error: attribute defaultNavHost (aka ...) not found, ttribute navGraph (aka...) not found

Tags:

android

xml

I tried to implement the Navigation feature in my app. When I try to build the app the output says:

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.

Here is the nav_host_fragment from activity_main.xml:

        <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" />

I have implemented navigation in my app level build.gradle:

    implementation "androidx.navigation:navigation-ui-ktx:2.1.0-alpha02"

I am using Android Studio version 3.4

like image 940
Matipolit Avatar asked May 03 '19 17:05

Matipolit


2 Answers

Can you add to build.gradle of the project:

classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.2.0-alpha03"

and in 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"
like image 146
Cuong Nguyen Avatar answered Sep 27 '22 18:09

Cuong Nguyen


Only change your activity_main.xml: xmlns:app="http://schemas.android.com/apk/res-auto" to xmlns:app="http://schemas.android.com/apk/res"

like image 40
acalasanzs Avatar answered Sep 27 '22 18:09

acalasanzs