I started a new project and import previous dependency settings, And tried using by viewModel in activity. But I can't get the by viewModel reference, So I tried going to External libraries. The previous project has androidx.activity:activity-ktx:1.0.0 even though I didn't add implementation "androidx.activity:activity-ktx:1.0.0". you can see this happening at https://github.com/android/architecture-samples .
But When I try to start a new project and import setting from previous project, I can't get the
androidx.activity:activity-ktx:1.0.0. I don't unserstand previous project or the sample of google import this androidx.activity:activity-ktx:1.0.0 , and my new project do not import that. although the gradle setting and gradle version is same.
Android KTX is a set of Kotlin extensions to help your write concise and idiomatic code.
by viewModel extension is not available by default for a new android project and should be added using Android KTX, particularly androidx.fragment:fragment-ktx:'version'.
You may find other useful extensions you would like to add to project like
androidx.activity:activity-ktx:, androidx.lifecycle:lifecycle-livedata-ktx: etc. Each one adds some special "syntactic sugar" so don't hesitate to learn their possibilities.
Please, see reference Android KTX
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With