Use annotation processor in kotlin

948 Views Asked by At

I have a simple annotation in my processor like following:

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.TYPE) @Retention(RetentionPolicy.CLASS)
public @interface BundleBuilder
{
    // ...
}

This works in java files but as soon as I convert my file to kotlin, the import of the annotation is not working anymore. Why?

enter image description here

What do I need to change to get his annotation working in kotlin as well? From the docs I can see that kotlin is 100% compatible with java annotations so I'm a little bit confused here what's the problem... I would understand if the processor is not working and needs to be adjusted to work with kotlin, but I don't know why the import itself does not work...

The library I'm talking about is here: https://github.com/MFlisar/BundleArgs

1

There are 1 best solutions below

3
On BEST ANSWER

I think you should use kapt for annotation processing in your build.gradle. After all, clean and rebuild your project so.

apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

//...

dependencies {
    compileOnly 'com.github.MFlisar.BundleArgs:bundleargs-annotation:1.3'
    kapt 'com.github.MFlisar.BundleArgs:bundleargs-processor:1.3'
}

repositories {
    maven { url "https://jitpack.io" }
}