I am trying to begin creating a javax annotation processor, im doing it from android studio for now. I just need the gradle dependency i think for it. Right now in gradle i have the following which i have tried:
provided 'javax.annotation:jsr250-api:1.0'
but when i try to build the following class it says it cant find AbstractProcessor class:
class MyAnnotationProcessor extends AbstractProcessor{
}
How do i get it to recognize this class ?
here is the exact error:
and my imports look like this:
and here is my java version:
$java -version
Picked up JAVA_TOOL_OPTIONS: -Xmx512m -Xms64m
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
AbstractProcessor is not accessible in android library module. To make it work, you can create a separate "java library" module and add its dependency in your main module. Below is the step by step description of the solution what worked for me:
Now create a new class CustomAnnotationProcessor in this library and extend the AbstractProcessor
Following is the snapshot of my Custom annotation processor:
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.lang.model.element.TypeElement;
public class CustomAnnotationProcessor extends AbstractProcessor{
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
return false;
}
}
Add compile options in your app/build.gradle to java 1.7. see following snapshot:
Add dependency of this newly created module in your main module
Compile and Run..!!
Don't forget to upvote if you liked my answer :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With