Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 774
Manish Kumar Avatar asked May 26 '17 14:05

Manish Kumar


2 Answers

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

like image 171
Edwin Nyawoli Avatar answered Oct 30 '22 21:10

Edwin Nyawoli


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"
like image 4
NM Naufaldo Avatar answered Oct 30 '22 21:10

NM Naufaldo