udacity / andfun-kotlin-sleep-tracker-with-recyclerview

Other
102 stars 229 forks source link

Gradle Errors #30

Open KellieHale opened 1 year ago

KellieHale commented 1 year ago

I tried to run the program with the step one changes but keep running into gradle errors. When attempting to update the gradle file to more current versions, we still get crashes due to uneditable files needing edits.

KellieHale commented 1 year ago

Here are the required updates for this project to work.

build.gradle

buildscript {

    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.3.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.20"
        classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.5.3")

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

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

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

Remove the optionals from the ViewModelFactory overrides, the SafeArgs and ViewModel library updates require non-nullable types.

class SleepQualityViewModelFactory(
        private val sleepNightKey: Long,
        private val dataSource: SleepDatabaseDao) : ViewModelProvider.Factory {
    @Suppress("unchecked_cast")
    override fun <T : ViewModel> create(modelClass: Class<T>): T {
        if (modelClass.isAssignableFrom(SleepQualityViewModel::class.java)) {
            return SleepQualityViewModel(sleepNightKey, dataSource) as T
        }
        throw IllegalArgumentException("Unknown ViewModel class")
    }
}

Please remove the variables that shorthand the versions for library implementations. It disallows the built-in linter to look for old libraries. Some libraries in this project are 24 months old.

If you are planning on selling this course to students, please make sure that the starter projects are up to date with current Android technologies.