2

将 Android Studio 升级到 4.0 版本后,Lombok 注释停止工作。在升级之前,相同的代码正在编译,没有错误。

编码:

    import lombok.AllArgsConstructor;
    import lombok.Builder;
    import lombok.Getter;
    import lombok.experimental.Accessors;

    @Getter
    @Builder
    @Accessors(fluent = true)
    @AllArgsConstructor
    public class UrlData {

        private int id;
        private String url;

    }

尝试编译时,我收到以下警告,最后出现错误(不确定所有警告是否相关):

> Task :mycorelib:kaptDebugKotlin
[WARN] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: org.greenrobot.eventbus.annotationprocessor.EventBusAnnotationProcessor (NON_INCREMENTAL).
> Task :app:kaptMyPrjDebugKotlin
warning: unknown enum constant KotlinClass$Kind.CLASS
  reason: class file for kotlin.jvm.internal.KotlinClass$Kind not foundwarning: You aren't using a compiler supported by lombok, so lombok will not work and has been disabled.
  Your processor is: org.jetbrains.kotlin.kapt3.base.incremental.IncrementalProcessingEnvironment
  Lombok supports: OpenJDK javac, ECJ
error: cannot find symbol
        startActivity(WebViewActivity.getIntent(getActivity(), urlData.url()));
                                                                       ^
  symbol:   method url()
  location: variable urlData of type UrlData

有没有办法解决这个问题,或者我应该将 lombok 删除为不受支持?

4

1 回答 1

1

诀窍似乎是忽略 Studio 的/IntelliJs 建议,用 the 替换compileOnly-lombok 行annotationProcessor并将这两行都保留在 build.gradle 中:

compileOnly 'org.projectlombok:lombok:1.18.16'
annotationProcessor 'org.projectlombok:lombok:1.18.16'
于 2020-11-07T09:10:32.657 回答