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
117
votes
17 answers

Hilt Unsupported metadata version in Kotlin

I was tried to run my code in Kotlin 1.5.10 With plugin as plugins { id 'com.android.application' id 'kotlin-android' id 'kotlin-kapt' id 'dagger.hilt.android.plugin' and dependencies as below dependencies { ... //Dagger - Hilt …
95
votes
1 answer

How to inject application context in a repository with Hilt?

I want to inject an application context into a repository class to create a room database instance inside the repository. I am using Hilt for dependency injection. Can we use hilt for passing application context or do I have to manually pass it? I…
Tushar
  • 1,076
  • 1
  • 9
  • 11
91
votes
8 answers

Set dynamic base url using Retrofit 2.0 and Dagger 2

I'm trying to perform a login action using Retrofit 2.0 using Dagger 2 Here's how I set up Retrofit dependency @Provides @Singleton Retrofit provideRetrofit(Gson gson, OkHttpClient client) { Retrofit retrofit = new Retrofit.Builder() …
Renjith
  • 3,457
  • 5
  • 46
  • 67
84
votes
8 answers

error: cannot find symbol @dagger.hilt.InstallIn(value = {ApplicationComponent.class})

After upgrading dagger hilt(version: 2.31-alpha) ApplicationComponent.class can not find. What is the alternative for a Component like RoomDatabase? @Module @InstallIn(ApplicationComponent::class) class RoomModule() { private val DATABASE_NAME =…
Mostasim Billah
  • 4,447
  • 3
  • 19
  • 28
65
votes
4 answers

DefaultActivityViewModelFactory not found

After migrating the Hilt version from 2.33-beta to 2.35 my project has stopped building with the error given below: A txt version: error: cannot access DefaultActivityViewModelFactory class file for…
Patryk Kubiak
  • 1,679
  • 2
  • 11
  • 17
63
votes
10 answers

The Hilt Android Gradle plugin is applied but no com.google.dagger:hilt-android-compiler dependency was found

I'm getting the error "The Hilt Android Gradle plugin is applied but no com.google.dagger:hilt-android-compiler dependency was found." while building the project. Here's how I'm adding hilt to my project.
Feroz Khan
  • 2,396
  • 5
  • 20
  • 37
62
votes
7 answers

Expected @HiltAndroidApp to have a value. Did you forget to apply the Gradle Plugin?

I have Google this problem, but the results are not work for me. The detail as following. public final class App extends com.zhixin.wedeep.common.BaseApplication implements androidx.lifecycle.LifecycleOwner { ^ // Expected…
Cyrus
  • 8,995
  • 9
  • 31
  • 58
59
votes
14 answers

Plugin [id: 'dagger.hilt.android.plugin'] was not found in any of the following sources

I get the following warning when I want to use @AndroidEntryPoint which is a property of hilt in my project. Expected @AndroidEntryPoint to have a value. Did you forget to apply the Gradle Plugin? (dagger.hilt.android.plugin) When I try to add id…
Hasan Kucuk
  • 2,433
  • 6
  • 19
  • 41
54
votes
5 answers

Dagger Hilt 'Assisted' and 'ViewModelInject' is deprecated. in Dagger Hilt View Model 1.0.0-alpha03

In Dagger Hilt View Model 1.0.0-alpha01 implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha01" implementation 'com.google.dagger:hilt-android:2.28-alpha' kapt 'androidx.hilt:hilt-compiler:1.0.0-alpha01' kapt…
Elye
  • 53,639
  • 54
  • 212
  • 474
52
votes
2 answers

Is ApplicationComponent deprecated?

I just started using Dagger Hilt for dependency injection on Android and I get a warning on Android Studio saying 'ApplicationComponent' is deprecated. Deprecated in Java. I didn't find anything related to this warning while Googling, is it actually…
Kostas Andrianos
  • 1,551
  • 2
  • 16
  • 21
52
votes
11 answers

Expected @AndroidEntryPoint to have a value. Did you forget to apply the Gradle Plugin?

When I am using Hilt in android with Room I got this kinda error. The full log is here: home/someone/Desktop/Calculator/app/build/tmp/kapt3/stubs/debug/com/hamidjonhamidov/calculator/MyApplication.java:7: error: [Hilt] public class MyApplication…
Khamidjon Khamidov
  • 6,783
  • 6
  • 31
  • 62
51
votes
3 answers

warning : The following options were not recognized by any processor: '[dagger.fastInit, kapt.kotlin.generated]'

I get this warning when I try to run or build an app in Android Studio. Why am I getting this? Do I need to heed this warning? The following options were not recognized by any processor: '[dagger.fastInit, kapt.kotlin.generated]'
Bincy Baby
  • 3,941
  • 5
  • 36
  • 62
40
votes
6 answers

Inject context with Hilt: this field leaks a context object

I'm using Hilt to inject context and other dependencies into my HomeViewModel class; Everything is working properly but I'm getting this warning. How can I prevent from leakings? This is my HomeFragment (where I inject and use the HomeViewModel…
Tarsila Costalonga
  • 924
  • 2
  • 11
  • 21
40
votes
12 answers

Cannot create instance of viewmodel after using Hilt in Android

Here is my AllFilesListViewModel class. class AllFilesListViewModel @ViewModelInject constructor( private val pdfItemRepository: PdfItemRepository):ViewModel() { } Here is PdfItemRepository class. @Singleton class PdfItemRepository @Inject…
Rajesh kumar
  • 982
  • 1
  • 9
  • 17
37
votes
3 answers

Injecting a repository into a Service in Android using Hilt

I have an Android project with Hilt dependency injection. I have defined MyApplication and MyModule as follows. @HiltAndroidApp class MyApplication : Application() @Module @InstallIn(ApplicationComponent::class) abstract class MyModule { …
MikkoP
  • 4,864
  • 16
  • 58
  • 106
1
2 3
88 89