Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android : `androidx.navigation.NavArgs` not found

I fetch this below code from From Codelab for navigation controller

But getting this below error: spend already more the 3 hours but not any success. Here is my error

Please help me to solve this error.

like image 952
Prashant Jajal Avatar asked Mar 02 '19 10:03

Prashant Jajal


People also ask

What is AndroidX navigation?

In its own words, AndroidX Navigation is “a framework for navigating between 'destinations' within an Android application that provides a consistent API whether destinations are implemented as Fragments, Activities, or other components.”

How do you enable your project to use navigation components?

In the Project window, right-click on the res directory and select New > Android Resource File. The New Resource File dialog appears. Type a name in the File name field, such as "nav_graph". Select Navigation from the Resource type drop-down list, and then click OK.

What is jetpack navigation?

Android Jetpack's Navigation component helps you implement navigation, from simple button clicks to more complex patterns, such as app bars and the navigation drawer. The Navigation component also ensures a consistent and predictable user experience by adhering to an established set of principles.


Video Answer


2 Answers

Change this

  implementation 'android.arch.navigation:navigation-fragment-ktx:2.2.0-alpha01'
  implementation 'android.arch.navigation:navigation-ui-ktx:2.2.0-alpha01'

to this:

  implementation 'androidx.navigation:navigation-fragment-ktx:2.2.0-alpha01'
  implementation 'androidx.navigation:navigation-ui-ktx:2.2.0-alpha01'

Notice that android.arch.navigation is replaced with androidx.navigation

also, make sure to apply this plugin on top of build.gradle:

apply plugin: "androidx.navigation.safeargs.kotlin"

and this to the dependencies to the project level build.gradle:

 classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.1.0-rc01"
like image 186
Amin Keshavarzian Avatar answered Oct 22 '22 17:10

Amin Keshavarzian


If you are using kotlin and androidX than replace this

apply plugin: "androidx.navigation.safeargs"

with

apply plugin: "androidx.navigation.safeargs.kotlin"

and in project level build.gradle

dependencies {
    classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.1.0-alpha01"
}

on app level build.gradle

def nav_version = "2.1.0-alpha01"

implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version" 

If you are using kotlin Ktx

implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"

Hope this will help other people also. It helps me too

like image 11
Harsh Mittal Avatar answered Oct 22 '22 15:10

Harsh Mittal