java – AllArgsConstructor from lombok is not found by Android Studio-ThrowExceptions

Exception or error:

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?

How to solve:

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

###

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 😀

###

I had the same problem after updating Android Studio.

None of the another answers including accepted one helped me.

Finally I have updated the lombok version to 1.16.20 (the latest for today) and the error disappeared.

Hope it will save time for someone.

###

Also:

If you target Java 8 in your Android project (e.g. by using retrolambda) this error will not appear.

###

@AllArgsConstructor(suppressConstructorProperties = true) solution is not working anymore. If you try this, you get the following:

This deprecated feature is no longer supported. Remove it; you can
create a lombok.config file with
‘lombok.anyConstructor.suppressConstructorProperties = true’.

The working solution is adding lombok.anyConstructor.suppressConstructorProperties = true to lombok.config file.

###

Annotation suppressConstructorProperties is now not supported by Lombok. If you try to remove (suppressConstructorProperties = true), you would be getting the following error:

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

Below are the steps to solve this problem:
1. Remove (suppressConstructorProperties = true) from the object.
2. Go to project level dir. in your app and create a lombok.config file.
3. Paste below code in the config file.

config.stopBubbling = true
lombok.addGeneratedAnnotation = false
lombok.accessors.chain = false
lombok.anyConstructor.suppressConstructorProperties = true

Leave a Reply

Your email address will not be published. Required fields are marked *