Questions tagged [dagger-hilt]

Hilt is a Dagger2-based dependency injection library for Android.

The goals of Hilt are:

  • To simplify Dagger-related infrastructure for Android apps.
  • To create a standard set of components and scopes to ease setup, readability/understanding, and code sharing between apps.
  • To provide an easy way to provision different bindings to various build types (e.g. testing, debug, or release).
1333 questions
7
votes
1 answer

Same fragment with different navgraph by hiltNavGraphViewModels

I followed single activity pattern for my app. My MainActivity has a bottom navigation with 4 fragments. nav_home and nav_video have same fragment so I want to HomeViewModel and VideoViewModel keep their states within these graphs. As you can see…
7
votes
0 answers

Android test are failing due to Hilt Dependency

I have following android test class @HiltAndroidTest @UninstallModules(PreferencesModule::class, CacheModule::class) class PlayerRepositoryTest { private val fakeServer = FakeServer() private lateinit var repository: PlayerRepository private…
nick.tdr
  • 4,627
  • 4
  • 28
  • 41
7
votes
4 answers

Execution failed for task ':app:kaptDebugKotlin'. > A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution

I'm getting this not very informative error while building my project in Android Studio. I've tried everything from stackoverflow but nothing works. Execution failed for task ':app:kaptDebugKotlin'. A failure occurred while executing…
Nenad Vukojevic
  • 73
  • 1
  • 1
  • 4
7
votes
4 answers

There are multiple DataStores active for the same file in HiltAndroidTest

I just added DataStore to our codebase. After that, I found that all sequential UI tests are failing - the first one in a test case pass but next fails with There are multiple DataStores active for the same file. I provide a data store instance…
Dawid Hyży
  • 3,581
  • 5
  • 26
  • 41
7
votes
1 answer

Inject a dao into Worker with Hilt problem

I have initiated a worker in my App class like below; @HiltAndroidApp class KutuphanemApplication:Application(),Configuration.Provider { @Inject lateinit var workerFactory: HiltWorkerFactory override fun getWorkManagerConfiguration() = …
7
votes
1 answer

Jetpack compose preview crashes with hiltViewModel<>()

I use compose version 1.1.0-beta03 and hilt-navigation-compose:1.0.0-beta01. this is my Composable code: fun EngagementBotChart(modifier: Modifier = Modifier) { val newHomeViewModel = hiltViewModel() AndroidView( …
Mobin Yardim
  • 695
  • 7
  • 17
7
votes
1 answer

How to share a viewmodel between NavGraph components (only)

I would like to share a viewmodel between many composables. Just like how we share a viewmodel between fragments within an Activity. But when I try this setContent { val navController = rememberNavController() NavHost(navController =…
clamentjohn
  • 3,417
  • 2
  • 18
  • 42
7
votes
2 answers

by viewmodels versus hiltviewmodel

When I want to share a view model between various views I would use by viewmodels. I recently began looking into hilt and was wondering if hiltviewmodel would accomplish the same thing? That is to allow me to share a single(same instance) of a…
james
  • 2,595
  • 9
  • 43
  • 70
7
votes
1 answer

@AndroidEntryPoint base class must extend ComponentActivity, (support) Fragment, View, Service, or BroadcastReceiver

I'm trying to use viewmodel and observe the data in my DialogFragment, I'm Injecting ViewModel as well, while implementing the code getting error. PFB my code snippet. And help me out with suitable solution. Current…
Amritesh Kumar
  • 207
  • 1
  • 5
  • 16
7
votes
2 answers

Hilt viewModel and Compose not working together

It seems like the official Android docs way of using Compose, Hilt and ViewModel injection with Navigation does not work. I have the following setup: A main screen, which only hosts the nav controller. The Home screen shows a button to. navigation…
dst
  • 1,770
  • 13
  • 26
7
votes
1 answer

@EntryPoint MainActivity must also be annotated with @Installin

I have been receiving this error on Dagger-Hilt and I don't know why, I even downgraded to a simple project to see if I could find my problem, but apparently I am doing everything correctly. I created the Application class, declared it on the…
Tony
  • 159
  • 1
  • 11
7
votes
3 answers

how can i use jectpack datastore in okhttp Interceptor? it need a context object

i wanna add a token to request headers in Interceptor . but now i dont now what should i do. here is my datastore val Context.dataStore: DataStore by preferencesDataStore(name = "settings") class SettingsManager(context: Context) { …
7
votes
1 answer

Dependency injection using hilt on singleton private constructor class

I'm new to hilt. So i want to try dependency injection with hilt on my project which use MVVM architecture. The structure look like this: JsonHelper -> RemoteDataSource -> Repository -> ViewModel. The problems occur when i try to inject my DI on…
rijamyazid
  • 251
  • 1
  • 2
  • 10
7
votes
4 answers

Getting error from creating a Hilt viewModel

I've tried to hand over a simple viewModel to a composable and get everytime this error and i don't know what it means: java.lang.IllegalStateException: Given component holder class com.example.app.MainActivity does not implement interface…
Chris Pi
  • 536
  • 1
  • 5
  • 21
7
votes
2 answers

Dagger Hilt: Scope dependencies for parent-/child-fragments

I am trying to find a solution in how to define Hilt in a certain fragment related scenario. I have the following setup: Activity Parent Fragment 1 Child Fragment 1 Child Fragment 2 ... Child Fragment n-1 Parent Fragment 2 Child Fragment…
Mordag
  • 487
  • 7
  • 20