dagger

Is it possible to integrate Dagger and AspectJ in an Android Studio project?

回眸只為那壹抹淺笑 提交于 2019-12-22 05:08:09
问题 I'm working in an Android project where I'm using Dagger for dependency injection. I don't know so much about Gradle, but as far as I understand, the Dagger annotations are processed by its compiler once the project is built. There's no problem in configuring it as the user guide says. Well, now I want to integrate AspectJ too, so I'm looking at one of the plugins for Android. However, it seems this plugin does a build post processing job to read the aspects too, which remains in conflict

How can I replace Activity scoped dependencies with mocks using Dagger2

删除回忆录丶 提交于 2019-12-21 17:49:14
问题 I have a scoped dependency in my Activity and I want to test that activity with some mocks. I have read about different approach that suggest to replace Application component with a test component during the test, but what I want is to replace the Activity component. For example, I want to test the Activity against mock presenter in my MVP setup. I believe that replacing component by calling setComponent() on Activity will not work, because Activity dependencies already injected via field

Dagger 2 : How to bind Fragment Map in parent component from subcomponent for FragmentFactory

允我心安 提交于 2019-12-21 12:29:14
问题 I have this Dagger 2 configuration: AppComponent.kt @Singleton @Component( modules = [ AndroidSupportInjectionModule::class, AppModule::class, ActivityBindingModule::class, ] ) interface AppComponent : AndroidInjector<AppApplication> { @Component.Builder abstract class Builder : AndroidInjector.Builder<AppApplication>() } ActivityBindingModule.kt @Module abstract class ActivityBindingModule { @ActivityScoped @ContributesAndroidInjector( modules = [ MainActivityModule::class, FragmentModule:

Dagger 2 : How to bind Fragment Map in parent component from subcomponent for FragmentFactory

可紊 提交于 2019-12-21 12:26:15
问题 I have this Dagger 2 configuration: AppComponent.kt @Singleton @Component( modules = [ AndroidSupportInjectionModule::class, AppModule::class, ActivityBindingModule::class, ] ) interface AppComponent : AndroidInjector<AppApplication> { @Component.Builder abstract class Builder : AndroidInjector.Builder<AppApplication>() } ActivityBindingModule.kt @Module abstract class ActivityBindingModule { @ActivityScoped @ContributesAndroidInjector( modules = [ MainActivityModule::class, FragmentModule:

Multiple versions of same library

*爱你&永不变心* 提交于 2019-12-21 05:10:49
问题 I have project A, which used to have module A1, that used dagger v. 1.2.2. Now I'd like to add to project A, module A2, that has dependency on dagger v. 2.0. But I can't because these two dagger libs are in conflict. Can I approach somehow multiple versions of library in different android modules? 回答1: You can't have both. You need to exclude the conflicting libraries from dependencies: configurations { all*.exclude group: 'com.google.android', module: 'support-v4' } dependencies { compile

VerifyError in multidex app when injecting dependency with Dagger

蓝咒 提交于 2019-12-21 04:59:13
问题 A sample app for library has ~67k methods. It has multidex enabled to overcome the 65k method limit. Unfortunately with multidex enabled the app crashes on VerifyError when trying to inject EndpointAdapter in main activity. This issue doesn't occur when the app is proguarded and the multidex is disabled, so it must be caused by multidex and Dagger 1 problems. I'm sure EndpointAdapter is in the main dex file, but some classes generated by Dagger are located in the second dex file generated by

dagger android support to androidx.fragment

时光毁灭记忆、已成空白 提交于 2019-12-20 17:33:24
问题 How to inject a fragment from the package androidx.fragment.app.Fragment ? I'm using the dagger-android framework to inject my dependencies in my code. As the documentation says I do this to inject my fragment @Override public void onAttach(Activity activity) { AndroidInjection.inject(this); super.onAttach(activity); // ... } the problem is that AndroidSupportInjection class accept only fragments of the package android.support.v4.app.Fragment or if I use AndroidInjection class only accept

Robolectric not using test application

爷,独闯天下 提交于 2019-12-20 12:38:33
问题 According to this link I can create a test application which Robolectric will automatically start using in tests. I cannot get this to work. I am using Dagger for dependency injection and have created injection wrapper classes for Activity and Application . Then each of my activities extends the wrapper activity class instead of plain old Activity . The problem I am having is that, in tests, the dependencies provided by the Application modules can't be resolved and so the tests fail. This is

Generic @Inject'd fields in an abstract superclass

别来无恙 提交于 2019-12-20 11:17:12
问题 Consider a MVP-ish set of types. An abstract Presenter exists, with a View interface: public interface View { //... } public abstract class AbstractPresenter<V extends View> { @Inject V view; //... } Then, lets have a specific concrete presenter subclass, with its view interface and implementation: public interface LoginView extends View { //... } public LoginPresenter extends AbstractPresenter<LoginView> { //... } public class LoginViewImpl implements LoginView { //... } In a Dagger module,

Dagger 2 - what is the purpose of a @Singleton annotation class

試著忘記壹切 提交于 2019-12-20 10:59:34
问题 From the dagger 2 Documentation I noticed that you can have a @Singleton annotated class. What is the purpose of marking a class as @Singleton as I have tried to do this in my code but a singleton object is NOT produced. I'm not clear on what use marking my class with this annotation serves. From the documentation please focus on the following statement: The @Singleton annotation on an injectable class also serves as documentation. It reminds potential maintainers that this class may be