how to get viewModel by viewModels? (fragment-ktx)
try
implementation 'androidx.fragment:fragment-ktx:1.1.0-beta02'
2021 UPDATE
This is no longer in beta. It works with the latest stable version at the time of writing. You will also need to import it in your fragment's Kotlin file.
implementation 'androidx.fragment:fragment-ktx:1.3.2'
import androidx.fragment.app.activityViewModels
Atlast we we have got stable version.
After moving to implementation 'androidx.fragment:fragment-ktx:1.1.0'
i faced another issue.
###Compiler Error:
Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6
###build.gradle (Module:app)
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
kotlinOptions {
jvmTarget = "1.8"
}
reference
After applying all the above the issue's is resolved.