Lombok Requires Annotation Processing

别来无恙 提交于 2019-11-27 17:06:24

问题


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 providing a link to settings.

Clicking on the notification does not take me to the right place.

What is the fix for this?


回答1:


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:




回答2:


With the newer gradle versions, it is enough to type these lines into the app's build.gradle's dependencies block:`

compile "org.projectlombok:lombok:1.16.16"
annotationProcessor "org.projectlombok:lombok:1.16.16"  

Sync the project with the gradle and it will work.




回答3:


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




回答4:


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.




回答5:


Probably marked answer was sufficient at the time but I struggled a bit with android studio 3 and lombok 1.16.18. Anyway following worked for me

in app > build.gradle add following

compileOnly 'org.projectlombok:lombok:1.16.18'
annotationProcessor 'org.projectlombok:lombok:1.16.18'

you may start getting other errors so if you in your MyApplication > lombok.config add following lines

lombok.addGeneratedAnnotation = false
lombok.anyConstructor.suppressConstructorProperties = true

if you don't have lombok.config just added it

Above were suggested by the developer of lombok in following posts
addGeneratedAnnotation
suppressConstructorProperties




回答6:


The setup guide from the lombok website(lombok set up for android) says we should do two things

1, install the lombok plugin

2, add gradle dependencies

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

But for me the plugin causes the problem to occur. After I disabled the plugin the error went away and lombok still works.




回答7:


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.




回答8:


Follow what setup manual says:

Gradle Make sure that the version of your android plugin is >= 0.4.3 Use the gradle-lombok plugin. If you don't want to use the plugin, add Lombok to your application's dependencies block (requires Gradle v2.12 or newer):

dependencies {    
 compileOnly "org.projectlombok:lombok:1.16.18" 
}

Android Studio Follow the previous instructions (Gradle). In addition to setting up your gradle project correctly, you need to add the Lombok IntelliJ plugin to add lombok support to Android Studio:

  1. Go to File > Settings > Plugins
  2. Click on Browse repositories...
  3. Search for Lombok Plugin
  4. Click on Install plugin Restart Android Studio

https://projectlombok.org/setup/android



来源:https://stackoverflow.com/questions/38911888/lombok-requires-annotation-processing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!