Lombok Requires Annotation Processing

前端 未结 10 937
不思量自难忘°
不思量自难忘° 2020-12-16 09:04

I\'m using Android Studio 2.2 Preview 7, and the Lombok plugin suddenly started saying: Annotation processing seems to be disabled for the project X, and provid

相关标签:
10条回答
  • 2020-12-16 09:57

    As of Android Studio v3.5 (august 2019) and prior, there wasn't setting for annotation processor. It is however sufficient to define in build.gradle in dependencies section :

    dependencies {
    ...
        compileOnly 'org.projectlombok:lombok:1.18.8'
        annotationProcessor 'org.projectlombok:lombok:1.18.8'
    ...
    }
    

    If Android studio still complains about "Lombok Requires Annotation Processing", for me it was Lombok plugin reinstallation and "Invalidate Caches / Restart" that fixed the problem.

    0 讨论(0)
  • 2020-12-16 09:59

    The Settings opened by clicking the notification are the Per Project settings, and those are not what you need in this case.

    To fix this, go to

    • File->Other Settings->Default Settings
    • Expand Build, Execution, Deployment
    • Expand Compiler
    • In Annotation Processors check Enable annotation processing
    • You may need to re-open the project to get the settings to take effect.
    • Enjoy

    For complete reference - screenshot with appropriate settings screen:

    0 讨论(0)
  • 2020-12-16 09:59

    First, I don't think removing your project from the welcome screen can have any effect. Just think about it, removing your project from "recent projects" on that screen does not re-create it, how could changing Default settings have any effect on an existing project?

    To enable annotation processing in an existing project you don't need to delete anything. Go to YourAwesomeProject/.idea/compiler.xml and make sure you have value "true" in following attribute: /project/annotationProcessing/profile@enabled.

    Like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <project version="4">
      <component name="CompilerConfiguration">
        ...
        <annotationProcessing>
          <profile default="true" name="Default" enabled="true"><!-- here -->
            <processorPath useClasspath="true" />
          </profile>
        </annotationProcessing>
      </component>
    </project>
    

    You might need to File -> Invalidate Caches / Restart

    0 讨论(0)
  • 2020-12-16 10:03

    For those who have the same problem using Android Studio 2.4+ its not solved by doing any hints above except Janis Peisenieks answer.

    Open your Intellij IDEA 2017 / Android Studio 2.4+ and go to (Windows)

    1. File->Other Settings->Default Settings
    2. Expand Build, Execution, Deployment
    3. Expand Compiler and choose Annotation Processors
    4. Make sure you have Enable annotation processing and "Obtain processors from project classpath" enabled
    5. Last but not least update your projects build.gradle file with the snippet below. Ignore the hint that its deprecated, since it's not using (until now. See issue).

      defaultConfig {
          javaCompileOptions {
              annotationProcessorOptions {
                  includeCompileClasspath = true
              }
          }
      }
      

    Found out that there is a very simple way doing this without all those changes above!

    If you set your processor in the gradle like lombok you wont use only provided or testCompile. You need to add this using annotationProcessor aswell into your dependencies. Example:

    dependencies {
        provided "org.projectlombok:lombok:1.16.16"
        annotationProcessor "org.projectlombok:lombok:1.16.16"
    }
    

    Thank you to Jack Wharton for butterknife where i figured out how he solved it.

    Hint: You may need to invalidate cache and restart to get it working for some annotation processors like lombok.

    0 讨论(0)
提交回复
热议问题