Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AllArgsConstructor from lombok is not found by Android Studio

Tags:

When I create a new Java class with one or more field and attach the @AllArgsConstructor annotation from lombok to it, then i get this message

Error:(9, 1) error: cannot find symbol class ConstructorProperties

from the on the Gradle Build console. I was able to reproduce this by creating a new empty Android project with this configuration.

The Class (never used or instantiated)

@lombok.AllArgsConstructor public class Model {     int foo;     String bar; } 

build.gradle:

dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:21.0.3' provided 'org.projectlombok:lombok:1.14.8' } 

@Getter and @Setter from lombok do not cause any problems and even the @NoArgsConstructor is not mentioned by gradle, so is the AllArgsConstructor if there are no fields.

Is this a bug from Lombok or is this bug located in front of the screen?

like image 972
Ohmen Avatar asked Jan 15 '15 17:01

Ohmen


2 Answers

Lombok generates the @ConstructorProperties by default for all generated constructors. On Android, that annotation is not available. As mentioned in the documentation it is possible to suppress the generation by either specifying suppressConstructorProperties=true for each @XxxArgsConstructor, or by using the following line in a high level lombok.config file:

lombok.anyConstructor.suppressConstructorProperties = true 

Disclosure: I am a Lombok developer

like image 170
Roel Spilker Avatar answered Oct 10 '22 16:10

Roel Spilker


You need to add suppression in your AllArgsConstructors. If you don't want to add a new config file, you can simply do this:

@AllArgsConstructor(suppressConstructorProperties = true) 

Disclosure: I'm not a Lombok developer :D

like image 42
Shubham Chaudhary Avatar answered Oct 10 '22 15:10

Shubham Chaudhary