3,203 questions
0
votes
1
answer
31
views
How to create two objects in Dagger Hilt with different life scopes?
I have a repository that should be Singletone as it holds state inside it. I provide it like this:
@Module
@InstallIn(SingletonComponent::class)
object RepoModule {
@Provides
fun ...
0
votes
0
answers
37
views
In Singleton lateinit property packageInfoData has not been initialized
I am an Android Developer.
I want to use Singelton with dagger hilt 2, I am using Jetpack Compose.
This is my code right now:
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class ...
1
vote
1
answer
194
views
Dagger 2.52 to use jakarta for the generated code
I have the following dagger 2.52 dependency in my project:
<dependency>
<groupId>com.google.dagger</groupId>
<artifactId>dagger</artifactId>
<version>2....
0
votes
1
answer
45
views
Android Test cannot execute Fragment instrumented tests with Dagger provided ViewModel, hitting NullPointerException on ViewModelProvider param owner
I have a fragment whose instance of ViewModel is provided by a component, scoped to the navigation graph of Main Activity. The Dagger app component was injected into the single Main Activity and ...
0
votes
0
answers
37
views
Assisted inject for factory method
I have a factory method:
public static MyDataService myDataService(DataFetcher dataFetcher, Config config)
I would like to crate an assisted factory out of it
@AssistedFactory
public interface ...
1
vote
1
answer
84
views
Is Hilt uses alpha version of Dagger’s KSP support under the hood?
In official Dagger documentation said:
Warning: Dagger’s KSP support is currently in alpha.
In Hilt release notes said:
Add KSP support to androidx.hilt.
So, my question is: is Hilt uses alpha ...
0
votes
1
answer
27
views
Injecting fragment's data into viewmodel using dagger2
I have a FooViewModel that is scoped to the FooFragment. In FooFragment, the device type is passed from another fragment based on what user selects. I want to inject this in the constructor of the ...
0
votes
0
answers
42
views
File name too long Dagger
Project Setup:
Dagger: 2.13 (no change)
Kotlin: 1.6.10 → 1.9.23
AGP (Android Gradle Plugin): 7.0.4 → 8.2.2
Kotlin DSL: 2.3.3 → 4.3.0
compileSDK: 33 → 34
Gradle: 7.0.2 → 8.2
Issue:
After updating my ...
0
votes
0
answers
10
views
How can I scope a binding for an external class with an Inject constructor?
Say I have class Foo living in some external module I can’t modify. It had an @Inject constructor. All of the dependencies of Foo are specified in my module, so it injects just fine, just unscoped. I ...
0
votes
1
answer
112
views
Hilt SingletonComponent vs ActivityComponent scope
I have an app with three activities.
Launch Activity A -> Activity B -> Activity -> C
Previous activity is finished while navigating to next activity.
I am injecting objects in Activity A and ...
-1
votes
2
answers
75
views
Mockito inject some mock objects and some real objects
I'm testing a function like this:
public class CsvUtilsTest {
@Mock
private S3Client s3Client;
@Mock
private S3BucketWrapper s3Buckets;
@Mock
CsvMapper csvMapper;
@...
-1
votes
1
answer
49
views
How to inject some but not all parameters
In my team's codebase I see classes that either have all parameters injected (and no constructor arguments) or have nothing injected. However, I'm wondering how to have a class with some injected and ...
0
votes
1
answer
51
views
Dagger2 injection across modules replace implementation of Interface
I am breaking up my project into different Android Studio modules. At the base, I have a headless modules with core business logic. Down the module dependency tree, I have an app modules that ...
0
votes
1
answer
35
views
Does Using ActivityComponent Scope in Hilt Provide the Same Dependency Instance Across All Fragments in the Activity
As we can see in the attached picture from the Google website,
The SingletonComponent will provide the same dependency instance across the application.
Is this the same for ActivityComponent? Will it ...
1
vote
0
answers
99
views
Activity Context VS Activity VS Activity Scoped Injection in Hilt
I have some questions regarding Hilt library based on this article I have read :
When (and When Not) to Pass the Activity Context in Android
Why we should inject Context instead of activity object in ...
0
votes
1
answer
177
views
Dagger2 multi-binding into a map with kotlin sealed class as key
In an android app, I'm using dagger2 for DI. I'm trying to multi-bind into a map, but getting build failures as shown below.
I have this module class in web module:
@Module
@InstallIn(...
0
votes
0
answers
30
views
How to create multiple instance of ViewModel using the old Dagger 2 approach?
Using the old ways with Dagger 2 for injecting ViewModel, how to create multiple instance of the same ViewModel for ViewPager?
@Singleton
class ViewModelProviderFactory @Inject constructor(
...
2
votes
1
answer
71
views
Is there some mapping between Maven version and Maven compiler plugin version?
I know the version of Maven
How do I know the version of Maven compiler plugin if it's not explicitly specified?
I'm asking this since a TeamCity build failed. Maven can't find a DaggerXComponent ...
-1
votes
1
answer
82
views
Not able to Inject from Java code into Kotlin Dependency Components
Using the latest version for Dagger 2,
implementation 'com.google.dagger:dagger:2.51.1'
annotationProcessor 'com.google.dagger:dagger-compiler:2.51.1'
kapt "com.google.dagger:dagger-...
1
vote
1
answer
329
views
Could not instantiate worker error when using WorkManager and Dagger-Hilt
I'm using Dagger Hilt for DI in my application. Whenever I try to inject my own dependencies in the constructor, WorkManager fails to initialize. But it works when I delete my own dependencies.
I set ...
0
votes
1
answer
53
views
Building dagger from source. issue with in kt_jvm_library . Bazel Build
All builds fail with "Error in kt_jvm_library"
Error log -
ERROR: /project/dagger/java/dagger/spi/model/BUILD:36:15: in kt_jvm_library rule //java/dagger/spi/model:model:
Traceback (most ...
2
votes
0
answers
161
views
How can I scope an object(not a ViewModel) to a compose navigation graph?
I have been struggling with this problem for a long time. It is finally time to ask StackOverflow. Let's say I have a compose navigation graph and I have a Logging object. I want the logging object to ...
2
votes
0
answers
32
views
DaggerAppComponent not creating in the version
Updated the dagger from the version 2.17 to 2.51.1. both the version not creating the DaggerAppComponent
error: cannot find symbol
import com.app.appscreens.auth.signup.DaggerSignupComponent;
Version:...
0
votes
0
answers
74
views
Execution failed for task ':app:kaptDebugKotlin' .Getting this error while working with setup of Dagger 2
Execution failed for task ':app:kaptDebugKotlin'. > A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction > java.lang.reflect....
0
votes
1
answer
170
views
Why doesnt Dagger @IntoMap & @ClassKey make any sense in Kotlin
im investigating the use of dagger to create and inject Set(s) into Maps with the kotlin code shown below
the first thing that doesnt make any sense is using kotlin @ClassKey(ErikTenHag::class),
even ...
0
votes
0
answers
12
views
Does Dagger2 support Custom InjectionResolvers similar to org.glassfish.hk2.api. InjectionResolver
My current android project employs Dagger/Hilt for dependency injection. I have a requirement for custom resolution of injected dependencies in part of this project. having researched dagger/hilt i ...
0
votes
1
answer
95
views
Dagger-2 cannot provide a dependency from another module
I've run into the fact that I can't inject a repository into my view model. I have two modules app and data. In I build all dependencies through Application Component
@Component(
dependencies = [...
0
votes
0
answers
27
views
Does Dagger 2 supports Instrumented Test in Android?
Is it possible to use Dagger 2 Android for instrumented test in a multi module project? I can't see related articles and SO question so here it is.
Custom runner
/**
* Custom AndroidJUnitRunner to ...
0
votes
0
answers
25
views
How do I modify my application to accommodate a Dagger @Provides method that now needs to accept runtime parameters?
I've got a @Provides method that instantiates a dependency client like:
@Provides
@Singleton
public DependencyServiceClient providesDependencyServiceClient() {
return new ClientBuilder()
....
0
votes
0
answers
53
views
How to provide a dependency from another module in Android Hilt
I have this situation with Dagger Hilt:
There are main_api and main_ui modules. Also cart_api and cart_ui. main_api contains IMain, and in main_ui has MainImpl (similarly in the cart module - ICart ...
0
votes
0
answers
39
views
Cannot resolve symbol 'AndroidSchedulers' in ViewModel - Java + Android Jetpack + Dagger2
I cannot, in any way, in my project, recognize the import of 'AndroidSchedulers'. I'm using the following imports (NOTE: IN MY PROJECT I USE THE VERSION CATALOG):
in my APP's build.gradle:
...
0
votes
1
answer
122
views
How to provide Retrofit in non-Android Module to an Android module?
Let me be more clear:
I have a multi-module app. There's the :app module, which is an Android module that I'm using Hilt to take care of dependency injection, and I also created a :network module that ...
0
votes
2
answers
96
views
Cannot create an instance of ViewModel with dagger-hilt
Cannot create a viewmodel class when injecting from a data module.
I have this module layer app -> feature -> data and i want to inject repository into viewModel
@HiltViewModel
class ...
0
votes
1
answer
248
views
cannot be provided without an @Provides-annotated method. public abstract static class SingletonC implements MyApplication_GeneratedInjector error
I want to learn clean architecture and I'm using hilt for di. Once I had java.lang.RuntimeException:
Unable to instantiate application com.example.cleanarchitecture.MainActivity package com.example....
1
vote
0
answers
129
views
Build performance Dagger2 vs Hilt
We have a large application with many modules.
There is a problem with the application build time, both the total time and the incremental time.
At the moment we are using Hilt as DI.
As you know, ...
0
votes
0
answers
76
views
Late init / dynamic dependency initialisation in Dagger
I've following scenario:
I have an Activity which performs some initialisation, when this initialisation is offer I'm able to construct a runtimeDependency.
This dependency I needed to create ...
0
votes
1
answer
230
views
IntelliJ Bazel and java_plugin can't recognize generated classes
I'm using IntelliJ, Bazel, Kotlin and Dagger2 in my project. Everything comiles just fine and works fine, but there is one big problem with this combination. IntelliJ doesn't see classes generated by ...
0
votes
0
answers
78
views
How to inject into an AppWidgetProvider() in java using dagger 2 - Android
I am using dagger 2 (version 2.37) and java in my android project. I want to inject ApiService to a class that extends AppWidgetProvider (which is a BroadcastReceiver). I followed steps on this ...
0
votes
1
answer
157
views
@HiltAndroidApp is unresolved after adding hilt-work dependency
I have working app. I use Hilt for di.
But when I tried to add HiltWorker - I get strange error with @HiltAndroidApp annotation, suddenly this annotation turns red and stops resolving.
This will ...
0
votes
0
answers
16
views
Error with viewmodel facotry and viewmodel module injecting thorugh Dagger, UninitializedPropertyAccessException: lateinit property viewModelFactory
I would like to show the one service result to the UI and the result has been modified dynamically. So, I have created MutableLiveData.
ResultViewModel
class ResultViewModel @Inject constructor(
...
0
votes
0
answers
123
views
Kotlin [Hilt] java.lang.reflect.InvocationTargetException (no error message) Error
I get the following errors when running the project, there is no problem in my codes, I think there may be a problem with the libraries I added, I am waiting for your help
MY build.gradle.kts (...
0
votes
0
answers
137
views
navigation.pop() does not work in navigation in decompose library
I created an application in jetpack compose using decompose. navigation.pop() does not work when clicking the back arrow in the top left corner. The application freezes and after a while I get this:
...
0
votes
1
answer
74
views
Dagger2 - Field injecting a variable in ViewModel. Is it problematic?
I learned dagger2 recently and came across a situation where I have to inject a variable of a class in my viewmodel.
Almost everywhere, its recommended to pass that variable through ViewModelFactory ...
1
vote
0
answers
50
views
Dagger2 to Hilt Migration Missing Binding
I am having a hard time with understanding how Hilt builds the dependency graph with the usage of EntryPoints. I have managed to use @HiltAndroidApp annotation within my Application class.
My main ...
1
vote
0
answers
47
views
Modern solution to inject dependencies in Service with Dagger
Can`t inject dependencies in service with Dagger
Spent a lot of time on finding solution for this question, but all answers is a bit old (2018-2019) and cant be implementend in that way as in answers.
...
8
votes
1
answer
854
views
How to scope an object instance to Jetpack Compose navigation graph lifecycle using Hilt?
Let's assume I have a multimodule Jetpack Compose project with feature modules and I want to scope some object instances to features lifecycles. For example, I want to scope AuthRepo instance to ...
1
vote
0
answers
159
views
Using Anvil with Jetpack compose - navigation with compose
I'm working on a new application, so we decided to work with compose and navigation with compose, but the deal is, we forced to use Anvil for DI,
so my question is: is there a better way to inject ...
2
votes
1
answer
78
views
There are multiple ways communicating between fragments? When should we use them?
There are multiple ways to communicate between fragments.
Shared ViewModel
Fragment Result API
Navigation Component
a. Safe Args
b. Arguments(Bundle)
Custom scoped ViewModel by using dagger2 ...
0
votes
0
answers
66
views
App is trying to open a layout of the aar fragment as if it is main app's fragment
I have an aar library (com.pg.clusive) with activities and fragments in it (it is like a mini app). When I implement it in the main app(com.pg.mainapp), I can start an activity from the aar without ...
1
vote
1
answer
745
views
Android : Unable to instantiate application
I have an app where I have implement dagger and when lunch my app I am getting this error :-
FATAL EXCEPTION: main
Process: com.heet.sleepmagic, PID: 18977
java.lang.RuntimeException: Unable to ...