87

When I try to add Safe Args (Android Navigation) to my app's as following

( using this guide : https://developer.android.com/topic/libraries/architecture/navigation/navigation-pass-data ) :

apply plugin: 'com.android.application'
apply plugin: 'androidx.navigation.safeargs'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'

android {...

I receive this error :

Plugin with id 'androidx.navigation.safeargs' not found.

AVEbrahimi
  • 17,993
  • 23
  • 107
  • 210
  • 1
    https://stackoverflow.com/questions/50284338/could-not-find-androidx-navigationsafe-args-gradle-plugin1-0-0-alpha01 – ecle Dec 25 '18 at 10:26
  • [Declaring Dependencies](https://developer.android.com/jetpack/androidx/releases/navigation#declaring_dependencies) | [SafeArgs](https://developer.android.com/jetpack/androidx/releases/navigation#safe_args) – Makc Sep 22 '21 at 14:55
  • For new gradle https://stackoverflow.com/a/71805989/8663316 – Faizan Haidar Khan Apr 09 '22 at 07:15

12 Answers12

130

In Android Studio bellow bumblebee

To add androidx.navigation.safeargsplugin follow below step's

  1. classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:2.4.2-alpha09"
    (latest) Add above to your Project Gradel file inside dependency block

  2. Then add apply plugin: 'androidx.navigation.safeargs' to your app/Module gradle file


In Android Studio bumblebee+

id 'androidx.navigation.safeargs' version '2.4.2' apply false
Leonardo Sibela
  • 1,613
  • 1
  • 18
  • 39
Anmol
  • 8,110
  • 9
  • 38
  • 63
66

You can use dependencies as below in Project level bulild.gradle in Android Studio bumblebee

id 'androidx.navigation.safeargs' version '2.4.2' apply false
Gayatri Patel
  • 816
  • 8
  • 8
27

Just add this line in your build.gradle project level :

 classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.2.0-rc02"
Sana Ebadi
  • 6,656
  • 2
  • 44
  • 44
18

In newer version of Android Studio 3.2+, below dependency need to add in both build.gradle file

Project-Level build.gradle

dependencies {
    classpath 'androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5'
}

App-Level build.gradle

plugins {
    id 'androidx.navigation.safeargs' 
}
Pratik Dodiya
  • 2,337
  • 1
  • 19
  • 12
13

Add this line in Project-level build gradle

 id 'androidx.navigation.safeargs' version '2.4.2' apply false

Add this in App-level build gradle

plugins {
id 'androidx.navigation.safeargs' 
}
Nikunj Patel
  • 321
  • 4
  • 5
12

It appears because you are declaring it in the wrong build.gradle file. You have to place it in the build.gradle that looks like this

buildscript {
    repositories {
        google()
    }
    dependencies {
        def nav_version = "2.1.0"
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
    }
}

This link explain how it is added https://developer.android.com/jetpack/androidx/releases/navigation#safe_args

Hanako
  • 1,637
  • 1
  • 13
  • 16
  • I have no file that looks like this :/ In my kotlin project (migrated from java) there is no "buildscript". They should make some tools to make these gradle files. Every my project is diffrent, because everything is diffrent after some time. – Kamil Oct 28 '22 at 10:45
  • @Kamil that's weird, try to create a new project and compare it to your current one. That's how you may match which is which – Hanako Nov 16 '22 at 23:09
12

Add

classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.1.0-alpha05"

In your project-level dependencies

For eg :

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

}

Don't forget to add the latest version

Shalu T D
  • 3,921
  • 2
  • 26
  • 37
Vinay John
  • 990
  • 12
  • 13
5

as per this https://developer.android.com/jetpack/androidx/releases/navigation

Add above to your Project Gradel file inside dependency block

`classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:2.2.1`

then add apply plugin: androidx.navigation.safeargs to your app/Module gradle file

Abednego
  • 599
  • 10
  • 17
2

I had to add it to the top level build.gradle, not sure if you've just added it to your app level build.gradle instead

George Yang
  • 694
  • 6
  • 18
1

FYI: I had to add it in this manner in order for it to work in Android Studio Dolphin | 2021.3.1:

Gradle Scripts > build.gradle (Project: YourProject)

plugins {
id blah
.
.
.
id 'androidx.navigation.safeargs' version '2.4.2' apply false

}

And also here:

Gradle Scripts > build.gradle (Module: YourProject.app)

dependencies {
implementation blah
.
.
implementation 'androidx.navigation:navigation-safe-args-gradle-plugin:2.6.0-alpha02'
testImplementation blah
androidTestImplementation blah

}

Elk
  • 51
  • 2
  • Well, it turns out that if you add safe args to your project in this manner, you get a bunch of duplicate class errors. So in reality, because safe-args must be in some other package, just adding the plugin like this: `id 'androidx.navigation.safeargs' version '2.5.2' apply false` worked or me. I just removed the implementation code. – Elk Oct 16 '22 at 16:35
  • Ok, well this answer only works to allow a sync and build. However, when you move to the next step of the tutorial at [Build Your First Android App](https://developer.android.com/codelabs/build-your-first-android-app#8) and apply your navigation between the FirstFragment and the SecondFragment you get a FirstFragmentDirections class not found error. After much searching and trying different fixes this answer [HERE](https://stackoverflow.com/a/70445647/666567) is what finally worked. – Elk Oct 17 '22 at 14:50
1

For me, adding this in the build.gradle (Project) worked.

id 'androidx.navigation.safeargs' version '2.4.2' apply false
Nijil Raj
  • 11
  • 2
-1

I hope this may help others. I followed the directions at developer.android.com and all the instructions here. None of them solved the issue for me. Mine was a simple order of operation in my modules build.gradle file.
I had: id 'androidx.navigation.safeargs.kotlin' listed as the first line in my plugins block.
moving to the end of the block solved my issue