Android Studio 2.4 + Lombok annotationProcessor configuration confusion

3.8k Views Asked by At

I using lombok on some project, and with the new Android Studio 2.4 Update now (Preview) I get this strange error:

What went wrong: Execution failed for task ':core:javaPreCompileRelease'. Annotation processors must be explicitly declared now. The following dependencies on the compile classpath are found to contain annotation processor. Please add them to the annotationProcessor configuration. - lombok-1.16.16.jar Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior. Note that this option is deprecated and will be removed in the future. See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.

I already tried:

annotationProcessor "org.projectlombok:lombok:1.16.16"

but has no effect.

I also tested:

android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true

But also has no effect.

Also checked the support page for further information but with no luck, anyone of you possibly? https://developer.android.com/studio/preview/features/index.html?utm_source=android-studio#annotationProcessor_config

2

There are 2 best solutions below

3
On BEST ANSWER

Update:

provided "org.projectlombok:lombok:1.16.16" // keep
annotationProcessor "org.projectlombok:lombok:1.16.16" // add this

Just worked perfectly, but I have two Android Studio modules, and two build.gradle files. The error log just changed a bit (module prefix), and I thought the fix didn't work.

But after applying the fix to both build.gradle files everything worked perfectly.

0
On

I had the same problem but needed a slightly different fix (although the idea came from the accepted answer above - https://stackoverflow.com/a/43820494/1777346)

Turned out I already had the provided and annotationProcessor in both build.gradle files.. but, I also had a compile entry. Removing it fixed this issue for me:

compile 'org.projectlombok:lombok:1.16.16' // remove this
provided 'org.projectlombok:lombok:1.16.16'
annotationProcessor "org.projectlombok:lombok:1.16.16"

Just figured I'd add my findings in case it helps anyone. I'm using Android Studio 3.0 Canary 4 and gradle:3.0.0-alpha4 in my unending quest to get build times down.. which never seems to pay off :)