Dagger not generating components for /test class

后端 未结 8 858
醉梦人生
醉梦人生 2020-12-04 20:57

I am following the guide here: https://github.com/ecgreb/dagger-2-testing-demo

I have the following setup in my app/src/main (the injection and @Provides code omitte

8条回答
  •  南笙
    南笙 (楼主)
    2020-12-04 21:34

    You need to add following to your build.gradle file for instrumentation test:

    androidTestApt 'com.google.dagger:dagger-compiler:'
    

    or for JUnit test:

    testApt 'com.google.dagger:dagger-compiler:'
    

    This is required to generate Dagger code for your test components.


    EDIT:

    If you are using jack tool chain then add following for android test:

    androidTestAnnotationProcessor 'com.google.dagger:dagger-compiler:'
    

    for JUnit tests:

    testAnnotationProcessor 'com.google.dagger:dagger-compiler:'
    

    EDIT:

    In case you are using kotlin-kapt for Kotlin code use following:

    kaptAndroidTest 'com.google.dagger:dagger-compiler:'
    

    or for JUnit test:

    kaptTest 'com.google.dagger:dagger-compiler:'
    

    Check this link for more info.

提交回复
热议问题