`by viewModels()` not resolving

Make sure that you have synced your changes with Gradle. If Android Studio still can’t find the import after that, you can add it in manually. It is:

import androidx.activity.viewModels