2

After upgrading Android studio to 4.0 version Lombok annotations stopped working. The same code was compiling with no errors before the upgrade.

The code:

    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;

    }

When trying to compile I am getting the following warnings and finally an error (not sure all of the warnings are relevant):

> 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

Is there a way to fix this or should I remove lombok as unsupported?

Maya
  • 349
  • 3
  • 15
  • please post your build.gradle file – Lena Bru Jun 07 '20 at 18:10
  • I tried different variants, versions. One of them: dependencies { compileOnly 'org.projectlombok:lombok:1.18.12' annotationProcessor 'org.projectlombok:lombok:1.18.12' testCompileOnly 'org.projectlombok:lombok:1.18.12' testAnnotationProcessor 'org.projectlombok:lombok:1.18.12' } – Maya Jun 08 '20 at 06:52
  • 1
    [works for me](https://github.com/alexcohn/Hello_Lombok.git) – Alex Cohn Jun 08 '20 at 17:03
  • @AlexCohn could you explain what you have done? – Jaco Jun 15 '20 at 14:44
  • @Jaco, no, I can not explain. I simply created a project afresh, and it worked. I could not reproduce the problem, that's why I could not post an answer to it. – Alex Cohn Jun 15 '20 at 16:39

1 Answers1

3

The trick seems to be to ignore Studio's/IntelliJs suggestion to replace the compileOnly-lombok line with the annotationProcessor and keep both lines in build.gradle:

compileOnly 'org.projectlombok:lombok:1.18.16'
annotationProcessor 'org.projectlombok:lombok:1.18.16'
Ivin
  • 1,081
  • 11
  • 21