Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.1K
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda