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

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.

4320 次浏览

恐怕不行为什么不在 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'

但是,要在 Kotlin 编写依赖模块,您应该按照以下方式配置 Gradle 脚本:

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

匕首需要注释处理工具在编译过程中生成依赖项代码。所以我想您只需要根据正确的语言使用正确的 APT (注释处理工具)。