dagger-2

Unresolved reference: DaggerTestComponent (Kotlin with Dagger for Test)

孤人 提交于 2020-01-11 06:43:46
问题 When we use Dagger and Kotlin, we'll need the following in our build.gradle dependency kapt 'com.google.dagger:dagger-compiler:2.0' compile 'com.google.dagger:dagger:2.0' provided 'org.glassfish:javax.annotation:10.0-b28' As stated in http://www.beyondtechnicallycorrect.com/2015/12/30/android-kotlin-dagger/ When I try to perform testing using Dagger, and generate the DaggerTestComponent.builder() as per https://labs.ribot.co.uk/fast-and-reliable-ui-tests-on-android-17c261b8220c#.o3efc5knx or

Unresolved reference: DaggerTestComponent (Kotlin with Dagger for Test)

空扰寡人 提交于 2020-01-11 06:43:07
问题 When we use Dagger and Kotlin, we'll need the following in our build.gradle dependency kapt 'com.google.dagger:dagger-compiler:2.0' compile 'com.google.dagger:dagger:2.0' provided 'org.glassfish:javax.annotation:10.0-b28' As stated in http://www.beyondtechnicallycorrect.com/2015/12/30/android-kotlin-dagger/ When I try to perform testing using Dagger, and generate the DaggerTestComponent.builder() as per https://labs.ribot.co.uk/fast-and-reliable-ui-tests-on-android-17c261b8220c#.o3efc5knx or

How to implement Dagger for worker classes?

女生的网名这么多〃 提交于 2020-01-10 03:34:04
问题 Since the Worker class is created by the framework ( WorkerManager ), how can we use @Inject fields into the Worker ? 回答1: You have to provide class using @Provides annotation in the module to inject. First create a component containing a module which will provide the class. @Component(modules = {Module.class}) public interface Component1{ void inject(SyncWorker syncWorker); } Module Class @Module public class Module{ @Provides public ISettingRepository getSettingRepo(){ return new

Error when generating code coverage report for androidTest instrumented testcases with dagger

狂风中的少年 提交于 2020-01-06 17:58:25
问题 I want to run createDebugCoverageReport gradle task.But after run task is failing and giving below error. java.lang.NoClassDefFoundError: dagger.shaded.auto.common.BasicAnnotationProcessor at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:324) at android.support.test.internal.runner.TestLoader.doLoadClass(TestLoader.java:92) at android.support.test.internal.runner.TestLoader.loadIfTest(TestLoader.java:113) at android.support.test.internal.runner

Error when generating code coverage report for androidTest instrumented testcases with dagger

假装没事ソ 提交于 2020-01-06 17:58:04
问题 I want to run createDebugCoverageReport gradle task.But after run task is failing and giving below error. java.lang.NoClassDefFoundError: dagger.shaded.auto.common.BasicAnnotationProcessor at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:324) at android.support.test.internal.runner.TestLoader.doLoadClass(TestLoader.java:92) at android.support.test.internal.runner.TestLoader.loadIfTest(TestLoader.java:113) at android.support.test.internal.runner

error: [Dagger/DuplicateBindings] com.example.StartRouter is bound multiple times?

荒凉一梦 提交于 2020-01-06 09:01:15
问题 I have a class StartRouter . I want to provide different instances of this class to each activity, and keep it alive as long as activity is alive (for that I made @ActivityScope ). Problem is that it does not do that in my code. It seems as dagger provides one instance per annotation, in my case, once for the @ActivityScope . This scope is a custom dagger scope. Here are my two modules (One for each activity), first module: @Module public class SplashModule { @Provides SplashVMFactory

Dagger2 Field Injection not working

无人久伴 提交于 2020-01-06 07:59:14
问题 I am familiar with Spring dependency injection, but Dagger2 is new to me. I am trying to get a simple java application working but field injection does not work. I have a class Main , that depends on a class MainBusiness which in turn depends on MainDao . MainBusiness gets injected into Main fine, but MainDao does not get injected into MainBusiness and throws a NullPointerException . Here is the MainDao that implements an interface IMainDao public class MainDao implements IMainDao { @Inject

Dagger2 Field Injection not working

99封情书 提交于 2020-01-06 07:59:10
问题 I am familiar with Spring dependency injection, but Dagger2 is new to me. I am trying to get a simple java application working but field injection does not work. I have a class Main , that depends on a class MainBusiness which in turn depends on MainDao . MainBusiness gets injected into Main fine, but MainDao does not get injected into MainBusiness and throws a NullPointerException . Here is the MainDao that implements an interface IMainDao public class MainDao implements IMainDao { @Inject

The annotation for provider function of dagger module class

岁酱吖の 提交于 2020-01-06 05:59:12
问题 I am developing an Android project with Kotlin and Dagger 2. I have a NetworkModule in which I define some provider functions. @Module object NetworkModule { @Provides @JvmStatic // Here uses @JvmStatic internal fun provideSomething(): Something { ... } } I see some people use kotlin @JvmStatic and some use dagger's @Reusable to annotate the provider function: @Module object NetworkModule { @Provides @Reusable // Here uses @Reusable internal fun provideSomething(): Something { ... } } And.

How do I inject an abstraction using an IOC container like Dagger 2

别等时光非礼了梦想. 提交于 2020-01-05 05:55:22
问题 What I would like to do is to have an abstraction, and pass the abstraction as parameter. So that if one day something better than retrofit comes along and I want to switch it, it will be easy to do so. Although I have no idea on how do it. Here is a basic overview of what I want to do: public interface ApiClient{ Object getClient() } public class RetrofitClient implements ApiClient{ private static Retrofit retrofit = null; @Override public Retrofit getClient(){ if(retrofit == null){