AllArgsConstructor from lombok is not found by Android Studio

后端 未结 6 1223
猫巷女王i
猫巷女王i 2020-12-09 16:50

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

Err

相关标签:
6条回答
  • 2020-12-09 17:03

    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

    0 讨论(0)
  • 2020-12-09 17:05

    Also:

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

    0 讨论(0)
  • 2020-12-09 17:06

    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
    
    0 讨论(0)
  • 2020-12-09 17:08

    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

    0 讨论(0)
  • 2020-12-09 17:12

    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.

    0 讨论(0)
  • 2020-12-09 17:25

    @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.

    0 讨论(0)
提交回复
热议问题