EDIT: Initial solution failed after I did some cleaning, also, it didn't work with Proguard. See updated solution below.
To solve this problem, I had to create my own custom annotation processor. The idea of this processor was to ensure processor order for the processors used by Lombok and Parceler.
Here are the steps I followed to resolve this problem:
Step 1
Create a new Java Module under the root project. Call it any name, for example parceler-lombok
, use any class name/package of your choice.
Step 2
Add lombok and Parceler annotation classes as dependency to the new module, and set source compatibility.
//File: parceler-lombok/build.gradle
apply plugin: 'java'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.projectlombok:lombok:1.16.16'
compile 'org.parceler:parceler:1.1.9'
}
sourceCompatibility = "1.7"
targetCompatibility = "1.7"
Step 3
Create the following directory in your main source folder for the module: src/main/resources/META-INF/services
Step 4
Create a file called javax.annotation.processing.Processor
inside the directory above.
Step 5
Edit the file, and add the following lines.
lombok.launch.AnnotationProcessorHider$AnnotationProcessor
lombok.launch.AnnotationProcessorHider$ClaimingProcessor
org.parceler.ParcelAnnotationProcessor
This is a declaration of all the annotation processors available in your module. The order shows that Lombok annotation processors should be loaded before parceler's
Step 6
Now that we have our "custom annotation processor", go back to your main app module, in your build.gradle file for app, do the following:
- Remove lombok dependency (annotatorProcessor, provided or compile) directive
- Remove the parceler annotationProcessor dependency (i.e.
org.parceler:parceler
), leave the API dependency as-is.
- Now add your custom annotation processor as a dependency
- Finally, ensure Java 1.7 compatibility
See snippets below :
//File: app/build.gradle
android {
//...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
//...
}
dependencies {
// ...
//Remove these ones
//provided 'org.projectlombok:lombok:1.16.16'
//annotationProcessor 'org.parceler:parceler:1.1.9'
//leave parceler API
compile 'org.parceler:parceler-api:1.1.9'
provided project(':parceler-lombok')
}
Using provided ensures that the annotation processor classes are not bundled with your app.
The following articles were very helpful: