Questions tagged [dagger-2]
Dagger 2 is a dependency injection framework for Java and Android. It implements the full stack with generated code
3,168
questions
0
votes
1
answer
23
views
Injecting a interface using variable injection in activity in android
Connection.kt
interface Connection {
fun connect(endpoint:String)
}
HttpsConnection.kt
class HttpsConnection @Inject constructor(): Connection {
override fun connect(endpoint: String) {
...
0
votes
1
answer
30
views
Dagger 2 class component not generated
i am facing issue from last 2 days. Currently , i am using Android studio Giraffe version. i am unable to get daggerComponent class. here is my code .
this is my app level gradle file
` plugins {...
0
votes
1
answer
40
views
Error [Dagger/DuplicateBindings] when working with enum
My android app has enum class Specialization:
enum class Specialization {
DEVELOPER, MANAGER
}
The values of this class are passed to the viewmodel, which makes a request to the repository based ...
1
vote
1
answer
28
views
Generic dagger errors since I modularized my app
Lately, I get totally unreadable errors when my project build fails. In the "Build Output" tab I just get the message e: Could not load module <Error module> with absolutely zero ...
0
votes
0
answers
35
views
Jetpack Compose and DI with Dagger 2
Recently I was working on a small project and thought of one thing about compose and dagger.
Usually I used Dagger with inject function that was dong everything for me but now it seems that it isn't ...
0
votes
1
answer
29
views
Dagger2 custom scopes: Are custom scopes not seen on @Inject constructor injections when using provider methods in a module?
The following is the code
Custom Annotation classes:
@Qualifier
@Retention(AnnotationRetention.RUNTIME)
annotation class CtxMain
@Scope
@Retention(AnnotationRetention.RUNTIME)
annotation class ...
0
votes
0
answers
20
views
Using Assisted Injection to inject savedStateHandle in ViewModel returning null argument value
I try to inject savedStateHandle using Dagger Assisted Injection following this link , I used backstack entry as the "SavedStateRegistryOwner" but somehow my argument in view model class ...
1
vote
0
answers
49
views
Resolving image URLs from a Composable
To resolve an image URL by width and aspect ratio I need to know the specific image URL schema that my image API uses. The width and aspect ratio is known in my UI module while the schema ...
0
votes
2
answers
37
views
Error using Hilt to inject OkHttpClient into AppGlideModule
I am trying to inject an OkHttpClient into an AppGlideModule using Hilt.
My network module provides the http client:
@Singleton
@Provides
fun provideOkHttpClient(
tokenInterceptor: ...
0
votes
1
answer
30
views
Dagger error: repeats modules with scoped bindings or declarations:
I keep trying to solve this error. And i have no idea what to do. I have 3 subcomponents(astronomy, currentweather and weatherforecast), I also created scopes and modules for each. With an App and ...
0
votes
1
answer
40
views
Dagger and Multiple AWS Lambdas
I am trying to use Java + Dagger to create a few basic lambdas to handle API Gateway requests.
I am trying to use Dagger to inject the AWS clients the different functions will need, but am struggling ...
0
votes
0
answers
24
views
Dagger Circular Dependency Deadlock
Is it possible for Dagger to deadlock while providing for dependencies? For example, there is a circular dependency between Class A and Class B because both inject each other like this:
class ClassA @...
0
votes
1
answer
15
views
Dagger framework having trouble when answering concurrent requests to the same endpoint
We have an application that retrieves image urls from a DB. The application is written in Dagger 2.25.4. When testing with Jmeter we have the following scenarios:
Single user performs 1000 requests --...
0
votes
0
answers
9
views
Inherit test Dagger component from main test Dagger Component with changes
I have a next component in main code AppComponent.kt`
@ApllicationScope
@Component(
modules = [
SomeClass::class,
SomeClass2::class,
SomeClass2::class,
....
...
0
votes
0
answers
55
views
When I use dagger in my kotlin project, I get an error
Suddenly I started getting this error, and I don't understand why. If anyone could just let me know where the error lies, that would be great.
This problem occurs when i use dagger implementation when ...
0
votes
1
answer
38
views
How to share ViewModel and its scope across fragments?
I have a small app where one ViewModel has been shared between Fragment and FragmentDialog. It shares not only logic, but also a state. It works fine until I have added one more fragment which uses ...
0
votes
0
answers
53
views
Dagger classes generated in build folder but unable to import them in a Java project using Dagger 2
I'm working on the Dagger 2 tutorial. I am using vscode along with build.gradle.kts. I can see in my build folder that the Dagger prefixed classes have been generated. However, vscode LSP doesn't ...
0
votes
0
answers
41
views
Execution failed for task ':app:kaptGenerateStubsDebugKotlin' Android studio
I have started learning dagger 2 dependency injection. For that I'm following a video tutorial and Android Developer Guide.
I have done what is written on the guide but facing this error. The error ...
0
votes
1
answer
202
views
I am getting this error when build the apps Execution failed for task ':app:kaptGenerateStubsDebugKotlin'
Execution failed for task ':app:kaptGenerateStubsDebugKotlin'.
'compileDebugJavaWithJavac' task (current target is 1.8) and 'kaptGenerateStubsDebugKotlin' task (current target is 17) jvm target ...
0
votes
0
answers
16
views
How to profile dagger 2 tree init
We have a big DI tree.
Now we want to find types that takes a huge time to create instance.
Create time is composition of: di dependency resolution, instance creation and instance init.
I can't find a ...
0
votes
0
answers
16
views
Abstracting multi module architecture with Dagger
Lets say I have a ModuleA-impl and a ModuleA-api and then I have a DomainModule that needs data from ModuleA. I want the DomainModule to depend on the api and not the impl itself. The problem is ...
0
votes
2
answers
26
views
Dagger2: Dependencies vs Modules
The implementation below gives and error suggesting that DataStore cannot be provided. I assumed that the UserPreferencesModule would provide this when the UserPreferencesComponent was included as a ...
0
votes
1
answer
43
views
@ContributesAndroidInjector's module alternative in Hilt
With Dagger2 we can add a module to @ContributesAndroidInjector so that the associated Activity or Fragment becomes available in the generated subcomponent. The official documentation is here: https://...
0
votes
3
answers
134
views
android(Hilt + Dagger2): provide context in domain module
I have a multi-module app where the app module depends on feature modules. I am trying to provide a dataStore object in my domain module but I require a context for this. However, Dagger can not ...
0
votes
0
answers
15
views
How to throw Qualifier inside the class? Dagger 2
I have a UseCase, which in the constructor accepts the implementation of the WallRepository interface. I have 2 implementations of this interface, which I have annotated with @NewsFeed and @...
0
votes
0
answers
83
views
How to use hilt for testing in a multi module android project?
I’ve couple of questions when trying to use hilt for testing in a multi-module project:
Say I’ve a feature module which declared some interface and its classes depend upon that interface. The ...
0
votes
0
answers
24
views
Execution failed for task ':app:kaptDebugKotlin' When using dagger2 in project
`Execution failed for task ':app:kaptDebugKotlin'.
A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction
java.lang.reflect....
0
votes
0
answers
141
views
Execution failed for task ':app:hiltAggregateDepsDebug'
In order to process annotations in my feature module I use dagger2. However everywhere else I am using Hilt. The problem I facing below started when I created a feature.gradle.kts which I have applied ...
0
votes
0
answers
72
views
How to setup Dagger with ViewModel and Saved State Getting ''getDefaultViewModelProviderFactory' overrides nothing' error
I'm using latest Dagger and latest AndroidX libs with Compose. I want to inject SaveStateHandler for my Activity and Compose, So i tried as mentioned on this article, but I'm getting below error on ...
0
votes
1
answer
505
views
Provide lazy injection using dagger hilt 2.42
Dagger hilt 2.42
I am trying to provide this class using lazy dagger injection.
class AlgoliaAnalyticsProvider @Inject constructor(
private val clientInsights: Lazy<ClientInsights>,
...
0
votes
0
answers
32
views
Dagger and Intellij Functional Testing configuration to allow debugging
I have an API written in Dagger with maven and it already has some Functional tests. When I run
mvn clean verify
The tests work correctly. However when I try to run them from the IDE, or debug them, ...
0
votes
1
answer
18
views
Problem following dagger tutorial, section 10 doesn't even compile
I have been trying to follow this tutorial:
https://dagger.dev/tutorial
But I have found several problems with it. The first problems occurs in the section https://dagger.dev/tutorial/01-setup, here ...
0
votes
1
answer
195
views
Dagger 2 Inject Dependency from custom scope inside my viewmodel
I am trying to create a custom scope for some of my objects, to use them in viewmodels and other places withing my app that do not belong in this scope.
This is what my component and subcomponent look ...
0
votes
1
answer
82
views
Is it possible to use Dagger components and modules from production code when writing Android UI Tests?
I have large android application with lots of library modules and dagger components, and I need to write Android UI tests for them. I don't want to create every single dagger component for each module....
-3
votes
1
answer
1k
views
Class handler.GameSessionLambda has no public zero-argument constructor: java.lang.Exception [closed]
I'm working with Lambda in Java and added Dagger2. However I'm having problem injecting objects to my lambda handler.
I'm getting the following error:
enter image description here
Class handler....
0
votes
1
answer
434
views
Android Hilt - Why can't I Inject a Dependency into MyViewModel without app complaining that my ViewModel doesn't have a zero argument constructor
Not sure What I have gotten wrong since I have followed the Hilt View Model Documentation as closely as possible.
I am trying to achieve the most basic of Dependency Injection in Android using Hilt, ...
1
vote
2
answers
542
views
Project with dagger not compile after updating to Android studio Flamingo 2022.2.1
Just updated to the new Android Studio version - Flamingo and my project does not compile anymore, with error:
error: cannot find symbol import package_name.DaggerAppComponent
Cause: class clojure....
0
votes
1
answer
29
views
Mock Injected private variable in Activity
class CustomActivity : BaseActivity() {
@Inject
lateinit var viewModelFactory: ViewModelProviderFactory
private val mViewModel: SplashViewModel by viewModels {
viewModelFactory
}
override fun ...
0
votes
0
answers
186
views
How to apply dagger 2 to compose desktop project
I have created a new Compose Multiplatform project with IJ Idea (single desktop platform).
Trying to add dagger to build.gradle.kts template:
import org.jetbrains.compose.desktop.application.dsl....
1
vote
0
answers
118
views
Build Failure with Dagger2 2.26 and KAPT: Resolving Version and Annotation Processing Issues in Gradle
I am unable to build my project, when i use dagger2 with kapt. This happened after i upgraded dagger2 2.20 to 2.45.
My build.gradle.kts configuration:
plugins {
kotlin("jvm") version &...
0
votes
1
answer
62
views
dagger-android and first creation of DispatchingAndroidInjector
I am working on speeding up the app launches. I am seeing that the very first creation of a ~1400 entries map of DispatchingAndroidInjector takes more than 2 seconds.
My theory is that each entry in ...
1
vote
1
answer
55
views
Creating multiple instances of feature set using Dagger2 instead of @Singleton
I have a set of Fragments and ViewModels that use a shared dependency (ProfitStore) that is injected with Dagger2. Previously this dependency was marked @Singleton in its provider. This worked fine ...
0
votes
1
answer
318
views
Workers cannot be instantiated with NoSuchMethodException in minified variant
I am using Android's WorkManager for background tasks and everything works great until I am trying to use it in a minified build. When the service should be initialized I am getting the following ...
0
votes
1
answer
671
views
Kotlin Dagger Hilt missing binding
How do I fix this binding issue:
C:\Users\win 10\Desktop\5. code-app\app\build\generated\hilt\component_sources\benchmark\com\Application_HiltComponents.java:137: error: [Dagger/MissingBinding] com....
0
votes
0
answers
78
views
Dagger deprecated modules
I am new to Dagger. I am creating a simple application using MVVM and retrofit and Dagger in android. I created 2 Modules - AppModule and NetworkModule.Added these modules to my Appcomponent. In my ...
0
votes
0
answers
101
views
Anvil: contribute multibinding in a module (not in component)
I have defined this classes for contributing some objects:
interface NavGraphScope
interface NavGraphIdProvider {
val navGraphId: Int
}
and have some implementations like
@...
0
votes
0
answers
48
views
Hilt for an android library
I have the following scenario to be executed :
One common SDK for common network layer. This will provide dependencies for okhttp & retrofit.
One feature SDK that uses common SDK for its network ...
0
votes
0
answers
73
views
hilt @optionalInject failing to create instance of ViewModel for non Hilt activity
I have a bottomsheet that is being used in several activities. It has been converted over to using Hilt however the other parts that use it have not. I found the @OptionalInject from the migration ...
0
votes
0
answers
127
views
Android - Passing a repo dependency into a ViewmodelFactory on a multi-module project using dagger2
I am using Dagger2 on a clean architecture multi-module project, Here's a simplified overview to detail my problem:
DataLayer -> SecondModule -> App
I have a repo-singleton which is in the data ...
0
votes
0
answers
70
views
Missing binding between View Model and Repository using Android Dagger-Hilt
My app uses the Sugar ORM instead of Room DB at the moment, however, I still would like to use some of the potentials of MVVM.
I set up the Dagger-Hilt in my app and made all connections needed. The ...