Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.1K
Views
Couldn't find `activityViewModels()` Hilt Android

I'm using Hilt and MVVM at my project and I want to get an viewModel from activityViewModel to use same in 2 activites. But my Android Studio says Unresolved Reference.

My app build.gradle is like this:

plugins {
        id 'com.android.application'
        id 'kotlin-android'
        id 'kotlin-kapt'
        id 'dagger.hilt.android.plugin'
    }

. . .

dependencies {

. .  .

implementation "com.google.dagger:hilt-android:2.38.1"
kapt "com.google.dagger:hilt-android-compiler:2.38.1"

implementation 'androidx.hilt:hilt-navigation-fragment:1.0.0'

implementation 'androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03'
kapt 'androidx.hilt:hilt-compiler:1.0.0'
. . .
}

My project build.gradle file is like this:

classpath 'com.google.dagger:hilt-android-gradle-plugin:2.38.1'

I'm trying to get ViewModel like this:

private val viewModel: SelectWifiViewModel by activityViewModels()
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

activityViewModels is used to get a reference to the ViewModel scoped to its Activity inside a fragment. If you want to used same ViewModel in both the activities, I would suggest you to switch to Fragments instead.

over 4 years ago · Santiago Trujillo Report

0

activityViewModels() has nothing to do with Hilt

you need a different dependency for that. It is in

implementation "androidx.fragment:fragment-ktx:1.4.0"
over 4 years ago · Santiago Trujillo Report

0

by activityViewModels() is a Kotlin property delegate from the fragment-ktx library.

try to add this dependency:

implementation "androidx.navigation:navigation-fragment-ktx:2.3.5"
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!