dagger-2

Can not resolve symbol DaggerApplicationComponent

与世无争的帅哥 提交于 2019-12-07 04:49:53
问题 I use Dagger2 with java and I got "Can not resolve symbol DaggerApplicationComponent error in my application." Seems there is something wrong with dependencies. Any help would be really appreciated. My complete code is here- https://github.com/rohitku860/AndroidMvpDagger2 Here is my app graddle with dependencies: apply plugin: 'com.android.application' android { compileSdkVersion 26 defaultConfig { applicationId "com.example.android.androidmvpdagger2" minSdkVersion 16 targetSdkVersion 26

Dagger 2 components not generated when using Jack

时光毁灭记忆、已成空白 提交于 2019-12-07 04:01:24
问题 When I enable the Jack compiler in Android Studio 2.2 the Dagger 2 component is not generated. Can Dagger 2 be used with Jack? If so, how would I go about configuring my application? From my application's build.gradle : jackOptions { enabled true } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } 回答1: I sunk like 2 days into figuring this out. So I'm circling back to posting the findings here in case it saves someone time: This is

How to @Inject members in BaseActivity using dagger.android?

风流意气都作罢 提交于 2019-12-07 03:45:28
This is my scenario: I want all my Activities to inherit from BaseActivity Within the BaseActivity , I want to inject Navigator (it helps me to manage the Fragments backstack and navigate between activities): abstract class BaseActivity : DaggerAppCompatActivity() { @Inject lateinit var navigator: Navigator @Inject lateinit var prefs: SharedPreferences // injected via AppModule.kt, see below. } The Navigator class needs a FragmentManager in its constructor: class Navigator @Inject constructor( val fragmentManager: FragmentManager) { // class body } I want to provide FragmentManager from a

Kapt not generating classes in Instant app feature module

末鹿安然 提交于 2019-12-07 03:38:40
问题 I am using dagger2 in my android application. It is not generating dagger component classes even though there is no errors. I have enabled the annotation processors in the setttings and restart my android studio but that didn't work for me. I read this thread too Dagger2 not generating Daggercomponent classes and read on one thread that apt is deprecated so I am using annotationProcessor Base Module build.gradle apply plugin: 'com.android.feature' apply plugin: 'kotlin-android' apply plugin:

dagger cannot inject type parameter field

折月煮酒 提交于 2019-12-07 00:36:20
问题 I'm working on an android application and I'm trying to inject a field which is type parameterized in an abstract class : BaseListFragment public abstract class BaseListFragment<E, A extends ArrayAdapter<E>, S> extends BaseFragment { @Inject protected S service; } But I get this following error at compile : error: cannot find symbol class S Here is my code for BaseFragment : public class BaseFragment extends Fragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate

Kotlin + Dagger2: cannot be provided without an @Inject constructor or from an @Provides- or @Produces-annotated method

自作多情 提交于 2019-12-07 00:33:24
问题 I'm getting the following error: Error:(8, 1) error: java.lang.String cannot be provided without an @Inject constructor or from an @Provides- or @Produces-annotated method. I'm stuck trying to make a module that provides two qualified Strings. Here is the simplified setup of dagger. @Singleton @Component(modules = [GreetingsModule::class]) interface AppComponent { fun inject(activity: MainActivity) } @Qualifier annotation class Spanish @Qualifier annotation class French @Qualifier annotation

Dagger 2 Scopes, where to place Presenters?

放肆的年华 提交于 2019-12-07 00:08:37
what would it be the best practice about placing Presenters in a Scope? Could we have Presenters on @Singleton or @AppScope without any problem? Should they be placed in an @ActivityScope in order to destroy them each time the activity is destroyed? what would it be the best practice about placing Presenters in a Scope? Usually a presenter should be in some scope. Not placing it in any scope will lead to problems, as every time you request a presenter it would create a new one. Which scope you choose mostly depends on your programming style, but the most common would probably be @PerActivity ,

Dagger2 custom @Qualifier usage

微笑、不失礼 提交于 2019-12-06 19:03:00
问题 Suppose I'm building a car and I have several Brake beans with different implementations class Car { @Inject Car(@BrakeType(value="abs")Brake frontBrake, @BrakeType(value="nonabs")Brake rearBrake) { } } @Qualifier @Retention(RetentionPolicy.RUNTIME) public @interface BrakeType { String value(); } interface Brake {} @BrakeType(value="abs") class AbsBrakeImpl implements Brake { @Inject AbsBrakeImpl() {} } @BrakeType(value="nonabs") class BrakeImpl implements Brake { @Inject BrakeImpl() {} } why

Unresolved reference dagger 2 + kotlin + android gradle

蓝咒 提交于 2019-12-06 18:27:52
问题 I'm testing out Dagger 2 with Kotlin in an Android project. I was inspired by the Android Clean Architecture repo. I have two modules in my gradle build, one is "app" and one is "module". Module contains one class call Model. In my app gradle module I created a dagger module called "DaggerModule" with a Model provider. When I try to build the project, I get compilation errors: DaggerModule.kt: (3, 57): Unresolved reference: Model DaggerModule.kt: (9, 34): Unresolved reference: Model

Dagger2 : How to use @Provides and @Binds in same module

瘦欲@ 提交于 2019-12-06 17:56:51
问题 I'm using the new Dagger2 (ver 2.11) and I'm using the new features like AndroidInjector , and ContributesAndroidInjector . I have an activity subcomponent, @Module abstract class ActivityBuilderModule { @ContributesAndroidInjector(modules = {UserListModule.class, MainFragmentModule.class}) @ActivityScope abstract MainActivity bindsMainActivity(); } @Module public abstract class MainFragmentModule { @ContributesAndroidInjector @FragmentScope @FragmentKey(UserListFragment.class) abstract