Home > Net >  How to add SafeArgs to new top level Kotlin gradle
How to add SafeArgs to new top level Kotlin gradle

Time:03-07

I m gonna use Navigation Framework with fragments but at the dependency step, when i tried to add SafeArgs from documentation i see that the new top level gradle file is different from documentation so i can't add it. Can you explain how to add SafeArgs to new kotlin top level gradle file ?

My top level gradle file :

plugins {
id 'com.android.application' version '7.1.2' apply false
id 'com.android.library' version '7.1.2' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false} 


task clean(type: Delete) {
delete rootProject.buildDir}

Documentation Top Level Gradle :

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

Thanks in advance.

CodePudding user response:

Your top level (project level) Gradle file is in Groovy, while the documentation is in KotlinScript. You need to copy and paste the document code in your top level Gradle file with a few changes like below:

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

Also, consider moving plugins definition to your app level Gradle file.

  • Related