Home > Software design >  How to add Navigation dependency to 7.x version of Gradle?
How to add Navigation dependency to 7.x version of Gradle?

Time:11-21

I created a new project due to a problem with an existing project.

I'm trying to add a dependency to a new project, but it's different from the gradle I've been doing so far.

I also went to the developer documentation, but it doesn't seem to have been updated for the new gradle yet.

Fortunately the app level gradle seems to be the same.


Previous gradle (Project)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = "1.5.21"
    def nav_version = "2.4.2"

    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.2.2'
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

        // safe args
        classpath("androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version")
        classpath 'com.google.gms:google-services:4.3.10'

        // Dagger Hilt
        classpath 'com.google.dagger:hilt-android-gradle-plugin:2.41'
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter() // Warning: this repository is going to shut down soon
    }
}

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

Current gradle(project)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.2.2' apply false
    id 'com.android.library' version '7.2.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
}

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

CodePudding user response:

You can add your dependencies above plugins block:

// Top-level build file where you can add configuration options common to all sub-projects/modules.


buildscript {
    dependencies {
        classpath 'com.google.dagger:hilt-android-gradle-plugin:2.40.5'
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.4.2"
    }
}

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

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

CodePudding user response:

You can add Navigation plugin to your Project Gradle like this:

id 'androidx.navigation.safeargs' version '2.5.2' apply false
  • Related