Cause: androidx.navigation.safeargs can only be used with an androidx project

Put classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.0" to your project build.gradle in buildscript.dependencies section.

But put apply plugin: 'androidx.navigation.safeargs' to your app build.gradle.


As per the Migrate to AndroidX, your gradle.properties file must contain the following lines:

android.useAndroidX=true
android.enableJetifier=true

That first line, android.useAndroidX=true, is what the androidx.navigation.safeargs.kotlin uses to ensure you are using an AndroidX project (it is also used by other tools in Android Studio to generate the right classes, such as when you are using any of the templates).


One other thing to remember is that apply plugin:"androidx.navigation.safeargs.kotlin" shouldn't be the top most apply on build.gradle.

This doesn't work:

apply plugin: 'androidx.navigation.safeargs.kotlin'
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

This works:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'androidx.navigation.safeargs.kotlin'

I think there is a bug. If your problem continues, you can try it like this. It worked for me too.

id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
id 'androidx.navigation.safeargs.kotlin'