Lombok: Not working with "Android room". Gives "error: Cannot find getter for field"

Created on 26 May 2017  Â·  16Comments  Â·  Source: projectlombok/lombok

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 error, that is "error: Cannot find getter for field".

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

Please help!!!

Most helpful comment

annotationProcessor MUST be in order.

compile 'org.projectlombok:lombok:1.16.20'
annotationProcessor 'org.projectlombok:lombok:1.16.20'

implementation 'android.arch.persistence.room:runtime:1.0.0'
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0'

All 16 comments

I have the same problem. Did you found any solution?
Anyone know if I can set the annotation processor order?

No, i did not found any solution for this.

Try using public modifier and write its getter and setter

Same problem..Is there any workaround for lombok and room to be working together?

any workaround for this issue ?

Not yet.

Change private to public, if you need this property private so add getter. This work for me.

annotationProcessor MUST be in order.

compile 'org.projectlombok:lombok:1.16.20'
annotationProcessor 'org.projectlombok:lombok:1.16.20'

implementation 'android.arch.persistence.room:runtime:1.0.0'
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0'

Ok, I'll check and let you know.

Like @s6mna9 said, annotationProcessor must be in order. After reorder - problem fixed.

For Room :

In my case

public String getpBSalesTotal() {
    return pBSalesTotal;
}

public void setpBSalesTotal(String pBSalesTotal) {
    this.pBSalesTotal = pBSalesTotal;
}

is the previous POJO class that i want as a table in my database.

I have just changed small "" p "" to capital ""P"" and that solved my error. Like below

public String getPBSalesTotal() {
    return pBSalesTotal;
}

public void setPBSalesTotal(String pBSalesTotal) {
    this.pBSalesTotal = pBSalesTotal;
}

to generate this type of

POJO form JSON

you can use this LINK. It worked for Room.

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"

@Zer0bee, does the solution @NMNaufaldo suggested work for you?

Oh, I already see a previous similar suggestion with confirmation, so I expect this to work.

Working fine now after reordering 'ap'.

Was this page helpful?
0 / 5 - 0 ratings