Lombok not working with "Android room". Gives "error: Cannot find getter for field"
Asked Answered
B

4

7

I'm using Lombok in android studio 3.0 preview with gradle 3.0.0-alpha1. I have following two annotation processor in my dependency:

annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha1"
annotationProcessor "org.projectlombok:lombok:1.16.16"

Now, If I use annotations from both dependencies in same class like:

@Entity(tableName = "test")
@Getter
public final class TestEntity {...}

It'll produce an error, that is:

error: Cannot find getter for field.

But if I remove any one of them, it'll work fine.

Any ideas/solutions?

Bane answered 26/5, 2017 at 14:14 Comment(0)
L
20

Reorder your annotation processor declarations. Move lombok up above the room compiler

Lemaster answered 4/7, 2018 at 16:7 Comment(0)
I
4

From Edwin Nyawoli answer, i just want to make it clear

In your build.gradle module file, reorder Lombok dependency above Room dependency

// Lombok
compileOnly "org.projectlombok:lombok:$lombok_version"
annotationProcessor "org.projectlombok:lombok:$lombok_version"

// Room
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
Iffy answered 13/12, 2019 at 17:44 Comment(0)
F
0

Are you using val in your model class? If yes, change to var

Formalize answered 5/7, 2017 at 12:56 Comment(1)
I'm writing code in java not in scala or kotlin, so i'm not using any of these var or val.Bane
S
-3

Try do it, it works for me.

public String getmState(){
    return mState;
}

change to

public String getMState(){
    return mState;
}
Separable answered 3/8, 2018 at 8:50 Comment(1)
That's an explicitly defined getter method. The original question was in regards to Lombok (projectlombok.org)Obstruction

© 2022 - 2024 — McMap. All rights reserved.