简体   繁体   中英

Use annotation processor in kotlin

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?

在此处输入图片说明

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

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" }
}

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