Lombok Requires Annotation Processing
Asked Answered
M

11

44

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.

enter image description here

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

What is the fix for this?

Madrid answered 12/8, 2016 at 7:5 Comment(0)
M
89

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: enter image description here

Madrid answered 12/8, 2016 at 7:5 Comment(4)
This only worked AFTER I removed the project from the Recent List (what shows when you start AS) and then re-add it.Wilmington
To be completely sure: Close the project. Delete the project from "Welcome to Android Studio" dialog (click the X). Click "Configure" in the bottom right and enable annotation processing as described above. Open your existing Android project again. Described in this answer https://mcmap.net/q/352004/-enable-annotation-processors-option-in-android-studio-2-2Catacomb
Changing Default Settings has zero effect unless you are creating a new project. The settings are already written in .idea/ And removing your project from the welcome screen does nothing to it. (Yes, I tried. It had zero effect. Then I realized it doesn't even make sense. :) /peaceHeighho
@JaroslavZáruba not true. I just removed from the welcome dialog and readded. Problem was fixed. That is the easiest solution.Climatology
M
19

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.

Marcellmarcella answered 19/6, 2017 at 15:45 Comment(3)
THis worked flawlessly for me on Android STudio 3.0 Canary 4, gradle-4.0-rc-1Kooima
Thank you. I tried a lot of another answers with butterknife and other. This helped me a lotRafat
Thanks that is solved my issuse ,Build was enable to run using gradlew but without gradle itselfPhotoneutron
O
16

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

Oreste answered 12/4, 2017 at 21:16 Comment(4)
Tried this and thought it works but it doesnt. Upvoted it aswell for the idea setting the compiler options, but it seems to store the data in the cache.Pierson
@EmanuelSeibold the point about caches is a good one, updated the answerHeighho
Thanks for this answer. Much simpler and more resilient than the approved answer.Pinchhit
how could changing Default settings have any effect on an existing project? I don't know why, but it does work to remove it from the welcome screen, I just tried it.Climatology
P
7

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.

Pierson answered 17/4, 2017 at 9:40 Comment(3)
Upvoted for the second half of your answer, fiddling with settings that are used for newly created projects makes no sense IMO :) /peace & thanks for the point about caches againHeighho
Point No 5. Worked for meFlofloat
There is no File / Other serttings in Intellij 2020Piroshki
S
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

Stockstill answered 6/1, 2018 at 12:41 Comment(0)
S
3

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.

Sextuple answered 26/4, 2019 at 5:50 Comment(0)
S
3

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.

Sharla answered 27/8, 2019 at 9:21 Comment(1)
reinstall lombok plugin and invalidate caches with restart helped meZareba
B
1

In AndroidStudio 3.5+ do next steps:

  • go to File -> Other Settings -> Preferences for New Projects... (!)
  • expand Build, Execution, Deployment
  • expand Compiler
  • select Annotation Processors
  • check Enable annotation processing

If it still wouldn't work just reinstall Lombok plugin.

Belshazzar answered 29/11, 2019 at 6:20 Comment(0)
R
0

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

Rhenium answered 29/11, 2017 at 20:12 Comment(0)
U
0
  1. install Lombok plugin and restart
  2. add dependencies : https://projectlombok.org/setup/gradle

    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'

this is worked for me.

Umpteen answered 12/2, 2020 at 12:15 Comment(0)
V
0

go to:

file => setting => Build,Execution,Deployment => Compiler => Annotation Processor

check: Enable annotation processing

enter image description here

Vanegas answered 4/1, 2023 at 23:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.