Questions tagged dagger-hilt

Explore the latest questions and answers asked by our top developers.

How to inject lambda(or interface) at runtime with hilt

I’m using hilt with MVVM, RecyclerView I wanna inject a lambda into the Adapter for receiving clickListeners from child views, but with @Module, I cannot create lambda at runtime. [Snippets below] // Lambda Listener class CustomAdapter @Inject constructor(private val listener: (clickedItem: Object) -> Unit) { override fun onBindViewHolder(holder: CustomViewHolder, position: Int) { holder.itemView.setOnClickListener { listener.invoke(clickedItem) […]

By sssrigo
Published
Categorized as android, dagger-hilt

Jetpack Compose + Hilt: java.lang.RuntimeException: Cannot create an instance of class ViewModel

I started trying jetpack Compose recently and used hilt & hilt-navigation-compose for my app. It works fine with the first ViewModel. However, when I try the same code on another ViewModel of my second screen, it always crashes with java.lang.RuntimeException: Cannot create an instance of class. But if I remove the parameter repository(Injected using Hilt) […]

Shared viewModel with assisted injection and hilt

I have an activity. This activity is receiving some arguments. At the moment, I’m able to create a viewModel with those parameters with assisted injection. //activity code private val viewModel: ViewModel by viewModels { val keyName = intent.extras?.getString(KEY_NAME).orEmpty() ViewModel.provideFactory(keyName) } Now, I have a navHostFragment and all the fragments in the nav graph will use […]

By YorchSircam
Published
Categorized as android, assisted-inject, dagger-hilt, viewmodel

Firebase phone auth with mvvm and Hilt

I’m working on developing an Android app with MVVM and dependency injection by Hilt that requires auth in with Firebase phone authentication, after many tutorial I capable of writing bellow FirebaseSource class, but I have an idea that I must provide it by a module to my repository and calling it’s functions from my viewmod, […]

By Ali
Published
Categorized as android, dagger-hilt, firebase, firebase-authentication, mvvm

What do these Hilt errors mean and why is my android 32 application now crashing on launch

having upgraded my android application to compileSdkVersion 32 buildToolsVersion "32.0.0" defaultConfig { applicationId "com.my.app" minSdkVersion 26 targetSdkVersion 32 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } i am now seeing these build messages > Task :app:hiltAggregateDepsStagingDebug WARNING: [Processor] Library ‘/Users/ulbrichtrw/.gradle/caches/transforms-3/16015df75f1841f59f18fa48255d2c0f/transformed/core-1.7.0-api.jar’ contains references to both AndroidX and old support library. This seems like the library is partially […]

By Hector
Published
Categorized as android, dagger-hilt

Way to share an dependency between class

I have three class needing to share a dependency. The latter is initialisated by one of them.The SettingsViewModel contains the data to initialize the dependency and it need to be deleted at the end of the activity. NetworkViewModel and TimeViewModel use it as an interface since the dependancy is an interface with the logic to […]

By Voliaman
Published
Categorized as android, dagger-hilt, kotlin

Sharing property between injected and provided classes which is cannot be provided by Hilt

In an old project, I need to refactor MVP architecture. But first I need to apply DI by using Hilt. I need to provide dependencies to presenter class and the I will inject my presenter class to my activity. Now some of my properties/dependencies cannot be provided. For example I couldn’t provide views. I tried […]

By K tas
Published
Categorized as android, dagger-hilt, dependency-injection, kotlin

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() = Configuration.Builder() .setMinimumLoggingLevel(android.util.Log.DEBUG) .setWorkerFactory(workerFactory) .build() I want to inject a singleton dao into my worker class for update something in DB. So I am injecting dao like below; @HiltWorker class ClearImageNotInArchiveWorker @AssistedInject […]

Modules that need to be instantiated by Hilt must have a visible, empty constructor

@Module @InstallIn(SingletonComponent::class) class WheelModule constructor(val size:Int) { @Provides fun provideWheel():Wheel = Wheel(size) } Modules that need to be instantiated by Hilt must have a visible, empty constructor. [Hilt] Processing did not complete. See error above for details. Source: Android Questions

By Pravin Desai
Published
Categorized as android, dagger, dagger-hilt, kotlin, module

Scoping RecyclerViewAdapter in Hilt

I am new to Dagger Hilt and trying to understand scopes. I want to provide RecyclerView Adapter using Dagger Hilt and I am using @Module @InstallIn(SingletonComponent::class) class AppModule { @Provides @Singleton fun provideAdapter(): TestAdapter = TestAdapter() } Is it best to provide Adapter this way? as I know we dont create Adapters as Singleton as […]

By faisal bashir
Published
Categorized as android, dagger-hilt, inject, scoping
1 2 3 66

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq