简体   繁体   中英

Do I really need to use kapt when there is no kotlin code?

The reason of this question is the next one: I have been using this library to make classes parcelable in Java, and I decided to migrate all the model to kotlin classes.

Reading some documentation I realised that I needed to use KAPT instead of "annotationProcessor".

The problem: The thing is that later when I was trying to run the app, I started to have problems with Dagger 2 and Butterknife which were using "annotationProcessor" as they are dealing with JAVA classes, not Kotlin classes. To get things working again I had to add a new line in my gradle file for every "annotationProcessor" but using "kapt" instead.

So my question is: Do I really need to do this if the code involved in using those frameworks are pure java classes? Can you explain me the reason of this in case I need to do it?

Thanks for taking the time to read this!

Yes, you need to do that.

Once you add Kapt to the project, it takes over annotation processing completely, so that the Java compilation tasks won't run any of the annotation processors. This is necessary in order to make the code generated from annotations in both Kotlin and Java available for the Kotlin compiler, which runs before javac.

As Kapt processes annotations in both Kotlin and Java files, using it for annotations in Java is the recommended way for Kotlin + Java projects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM