Using an Android SDK class in a custom annotation processor

51 Views Asked by At

I am trying to implement an annotation processor to fill views with a foreground color (nothing fancy for the moment). I have implemented my processor to process every Type annotation with my custom annotation. The process is going straight so far until I had to declare a variable inside a generated method with a type from Android SDK namely ColorDrawable the class generation is done successfully but there were missing an import for the Type ColorDrawable.java.

The problem is that since my processor is located inside a java library though I cannot reference ColorDrawable.class from there.

I am using the cool library JavaPoet to generate the java files. Is there any solution for this particular problem?

Thanks in advance!

1

There are 1 best solutions below

0
On

So after posting the same question to JavaPoet github repository I got the correct answer for this thread.

The trick is to call :

ClassName.get("android.graphics.drawable", "ColorDrawable")

The answer can be found here