"Prefer to run the dagger processor over that class instead" in Kotlin

AndroidKotlinDagger

Android Problem Overview


I'm getting this note in the build whenever I do an inject into a kotlin class (btw, I have a mixed android project with both kotlin and java).

For example, after this gradle task: compileStagingDebugJavaWithJavac (StagingDebug is my build variant), I get this message:

> "Note: Generating a MembersInjector or Factory for com.packageNameXXX.CourseDiscoveryMapFragment. Prefer to run the dagger processor over that class instead."

My CourseDiscoveryMapFragment code can be seen here:

class CourseDiscoveryMapFragment : Fragment(){

    @Inject
    lateinit var presenter: CourseDiscoveryMapPresenter

    lateinit var mapView: MapView

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {

        val view = inflater.inflate(R.layout.fragment_discovery_map, container, false)

        MapsInitializer.initialize(activity)

        mapView = view.mapView
        mapView.onCreate(savedInstanceState?.getBundle(BUNDLE_KEY_MAP_STATE))

        (activity as BaseActivity)
                .activityComponent.inject(this)
}

And my ActivityComponent is :

@ActivityScope
@Subcomponent(modules = ActivityModule.class)
public interface ActivityComponent {

    void inject(BaseActivity baseActivity);

    void inject(CourseDiscoveryMapFragment fragment);

    //Exposed to sub-graphs.
    Activity activity();
}

So, I'm having dagger component and modules written in Java, while having dagger injections in Kotlin.

Is this anything that I should be worried about?

Thank you.

Android Solutions


Solution 1 - Android

I am afraid you can't. Why not write dependency modules in Kotlin?

To write dependency modules in java, you need to configure your Gradle script in this way:

> compile 'com.google.dagger:dagger:2.8' > apt 'com.google.dagger:dagger-compiler:2.8'

But, to write dependency modules in Kotlin, you should configure your Gradle script in this way:

> compile 'com.google.dagger:dagger:2.8' > kapt 'com.google.dagger:dagger-compiler:2.8'

dagger need the annotation processing tool to generate the dependency code during the compiling process. So I guess you just need to use the right APT(annotation processing tool) according to right language.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFábio CarballoView Question on Stackoverflow
Solution 1 - AndroidJacobView Answer on Stackoverflow