Category : dagger

I am new at Kotlin and I am trying to create a ViewModel instance using dependency injection (dagger.hilt). I am getting "Cannot create an instance of class CoursesViewModel" error and I don’t know why. Could you help me with this? CoursesViewModel.kt class CoursesViewModel @ViewModelInject constructor( private val courseDao: CourseDao ) : ViewModel() { } AppModule.kt ..

Read more

I’m trying to use Dagger hilt in my project. I have an Activity that uses Databinding: @AndroidEntryPoint class MainActivity : AppCompatActivity(), SetGreeting { private lateinit var binding: ActivityMainBinding @Inject lateinit var fragmentFactory: FragmentsFactory override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = DataBindingUtil.setContentView(this, R.layout.activity_main) supportFragmentManager.fragmentFactory = fragmentFactory … } override fun greeting(msg: String) { binding.greeting.text = ..

Read more

I have project that was initially started with Java(contains dagger and moxy frameworks). I have added room dependency and I have create all room components in kotlin so as dependency I using: implementation "androidx.room:room-runtime:2.2.6" kapt "androidx.room:room-compiler:2.2.6" When I adding apply plugin: ‘kotlin-kapt’ I have dagger error: cannot find symbol DaggerAppComponent; When I try to add ..

Read more

I’m trying to use Dagger Hilt in my project. so I add these lines of code as the official documentation says: first, in my build.gradle (app) plugins { id ‘com.android.application’ id ‘kotlin-android’ id ‘kotlin-kapt’ id ‘dagger.hilt.android.plugin’ } … dependencies { implementation ‘androidx.legacy:legacy-support-v4:1.0.0’ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation ‘androidx.core:core-ktx:1.3.2’ implementation ‘androidx.appcompat:appcompat:1.2.0’ implementation ‘com.google.android.material:material:1.3.0’ implementation ‘androidx.constraintlayout:constraintlayout:2.0.4’ testImplementation ‘junit:junit:4.13.2’ androidTestImplementation ..

Read more

I want to make API request when ViewModel is initialized. That`s why I make API request inside init method; expecting init be triggered when I inject viewModel in Activity. What am I doing wrong? MainViewModel.kt @HiltViewModel class MainViewModel @Inject constructor(private val mainRepository: MainRepo) : ViewModel() { companion object { var TAG = "MainViewModel**" } init ..

Read more

I am currently wondering why I should include a network dependency that normally lives inside my :core module in my :app module. Dagger/Hilt is not capable of resolving my @Singleton OkHttp client which which is defined in :core inside a Hilt Module. It looks like this: // :core @Module @InstallIn(SingletonComponent::class) object MyModule { … @Provides ..

Read more

I need to change the base url which can be entered by user that means the base URL can be totally different each time user enters it. how could I achieve these. What i have tried. Retrofit2 Builder methods retrofit.newBuilder().baseUrl("www.google.com").build() But these is not overriding the base url which is provided while building the retrofit ..

Read more