Category : dependency-injection

enter image description here I try to implement dependency injection in android studio at the time i got this (Execution failed for task ‘:app:kaptDebugKotlin’. > A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution > java.lang.reflect.InvocationTargetExcep) error i don’t know how to solve it **Source code = ** https://drive.google.com/file/d/1y2NsQ5Vg8zk8WRd1KqasKfSYu4RkggxL/view?usp=sharing Source: Android Studio..

Read more

I’m using Dagger for DI and Retrofit for network. When i trying to call retrofits api method in my presenter, i catchs NPE. Here is Network module: @Module public class NetworkModule { String baseUrl; public NetworkModule(String baseUrl) { this.baseUrl = baseUrl; } @Provides @Singleton Gson provideGson() { GsonBuilder gsonBuilder = new GsonBuilder(); return gsonBuilder.create(); } ..

Read more

I was trying to learn manual dependency injection using Android’s documentation on the same. Following, their example, I created these 4 basic classes. NumeralSquared.kt package com.example.dependency_injection_practice import kotlin.math.pow class NumeralSquared { fun getSquare(number: Double): Int { return number.pow(2).toInt() } } Numeral.kt package com.example.dependency_injection_practice class Numeral(private val numeralSquared: NumeralSquared) { private var number: Int = 0 ..

Read more

I’m injecting with Dagger-Hilt a class with a dependency on @ActivityContext in a ViewModel, this module is installed in ActivityComponent and scoped to activity and it’s throwing me an error whenever I try to compile. For your information I have other modules with ActivityRetainedComponent and SingletonComponent injecting @ApplicationContext. Now I’m trying to figure out what ..

Read more

I got know about the Android dependency injection from https://developer.android.com/training/dependency-injection . the thing is without dagger2 we can create object like below and use it(Constructor Injection). what make sense to use Dagger2? The benefit of Design pattern to archive the below benefits Ease of Testing Reusability of Code Ease of Refactoring but my question is ..

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