Kotlin and Android Development featuring Jetpack:

There is an error when following steps to use the nav_version variable in project’s build.gradle of Penny_Drop.

Following the official documentation the way to use this variable is adding in the app’s build.gradle file: https://developer.android.com/guide/navigation/navigation-getting-started


dependencies {
  def nav_version = "2.3.5"

  implementation "androidx.navigation:navigation-fragment:$nav_version"
  implementation "androidx.navigation:navigation-ui:$nav_version"

  .......
}

Hey there!
What is the error you’re seeing with Penny Drop? I’m surprised that the variables aren’t working as they’ve been that way for the lifetime of the book.

Do make sure you’re using double quotes in the dependency lines as single quotes ignore variables. That’s thrown me off before.

Also, what you linked is absolutely valid as well. I just went with having variables in the project-level file since that was how Google defaulted things when I started the apps. If you wish to move variables into the dependencies block, that’s also just fine.

Let me know on what you’re seeing and we’ll get it fixed.

Thanks!

Thanks @mfazio23 for your answer :grinning_face_with_smiling_eyes:, I founded the error, I was using a code from beta version of the book, so now with the latest version it works, this is the updated code in build.gradle:

buildscript {
    ext {
        kotlin_version = "1.4.30"
        nav_version= "2.3.3"
    }
// other code 
}

Good, glad it’s working!