Closed pjuppes closed 9 months ago
Hello. I'm not sure if the buttons are working in the starting code but I'll help you getting the app running.
Here's the steps I did and got the app working
android:exported="true"
abstract class SleepTrackerViewModelFactory( private val dataSource: SleepDatabaseDao, private val application: Application) : ViewModelProvider.Factory { @Suppress("unchecked_cast") override fun <T : ViewModel> create(modelClass: Class<T>): T { if (modelClass.isAssignableFrom(SleepTrackerViewModel::class.java)) { return SleepTrackerViewModel(dataSource, application) as T } throw IllegalArgumentException("Unknown ViewModel class") } }
build.gradle(:app) `apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' apply plugin: 'androidx.navigation.safeargs'
android { compileSdkVersion 31 defaultConfig { applicationId "com.example.android.trackmysleepquality" minSdkVersion 19 targetSdkVersion 31 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }
// Enables data binding.
buildFeatures {
dataBinding true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// Support libraries
implementation "androidx.appcompat:appcompat:1.4.1"
implementation "androidx.fragment:fragment:1.4.1"
implementation "androidx.constraintlayout:constraintlayout:2.1.3"
// Android KTX
implementation 'androidx.core:core-ktx:1.7.0'
// Room and Lifecycle dependencies
implementation "androidx.room:room-runtime:$room_version"
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
kapt "androidx.room:room-compiler:$room_version"
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1"
// Kotlin Extensions and Coroutines support for Room
implementation "androidx.room:room-ktx:$room_version"
// Coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutine_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutine_version"
// Navigation
implementation "android.arch.navigation:navigation-fragment-ktx:$navigationVersion"
implementation "android.arch.navigation:navigation-ui-ktx:$navigationVersion"
// Testing
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
} build.grade(TrackMySleep....)
buildscript {
ext {
kotlin_version = '1.6.21'
archLifecycleVersion = '1.1.1'
room_version = '2.4.2'
coroutine_version = '1.5.2'
gradleVersion = '7.1.3'
navigationVersion = '1.0.0-alpha08'
dataBindingCompilerVersion = gradleVersion // Always need to be the same.
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:$gradleVersion"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:$navigationVersion"
// 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 }`
after updating to chipmunk you'll get an error I haven't found a fix yet I'll keep you posted
error: illegal start of expression
return .R.id.action_sleepQualityFragment_to_sleepTrackerFragment;
I spend like an hour on this every time.
you also need to upgrade the navigation version, change to the androidx implementation of the navigation libs, and use the androidx plugin for safe args.
it still has nav on 1.0.0 and is using the android.arch libraries instead of the androidx libraries
https://developer.android.com/jetpack/androidx/releases/navigation
None of the code examples works on Android Studie 2020.3.1 and jdk 16, a lot of mistakes, warnings. The gradle builts works, but the app don't start. Why don*t you build the programms from Beginning a new projekt