I have read the other threads on this but still can't get it to work. I've added,
def nav_version = "2.3.5"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
To the Project Gradle, and:
id 'androidx.navigation.safeargs'
To the app Gradle file.
I have:
android.useAndroidX=true
android.enableJetifier=true
in the gradle.properties file
I've followed the tutorials to the letter, adding argument but still I don't get the direction or any other classes generated once I rebuild the project.
What am I missing?
CodePudding user response:
Maybe you are using kotlin (as infered from your tags) and an alternative way is to use the plugin for Safe Args just in Kotlin:
build.gradle (:project):
buildscript {
ext.nav_version = "2.3.5"
dependencies {
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
}
}
build.gradle (:app):
plugins {
id 'androidx.navigation.safeargs.kotlin'
}
Verify:
- Kotlin >= 1.4
- Android Studio >= 4.2.
CodePudding user response:
Ok, the answer was found, thanks to @anshul: The problem is not that the files are not generated, they are. But, the IDE does not find them. As I am using Kotlin, the answer is a bit different from that for Java.
You must add to your app-level Gradle
android {
...
sourceSets {
main {
kotlin {
// srcDirs = 'build/generated/source/navigation-args/'
srcDirs = 'build/generated/source/navigation-args/debug/com/example/navanddata/ui/'
}
}
In my IDE, if you use the first (commented out) line, you get a multitude of folders that appear in your IDE sidebar. But if you go for the second, you must update it to your project name and update it for DBG / REL compilation.
In both cases, you will have to look for the files for a bit as they do not appear where you would expect, rather (in the second option) under a folder called Kotlin are “root level”.