How to use Android APT
This article mainly explains "how to use Android APT". Friends who are interested might as well take a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use Android APT.
Three swordsmen of Android AOP: APT, AspectJ, Javassist
Android APT
APT (short for Annotation Processing Tool) can parse annotations during code compilation and generate new Java files, reducing manual code input. Now many mainstream libraries use APT, such as Dagger2, ButterKnife, EventBus3 and so on.
Representative framework:
DataBinding
Dagger2
ButterKnife
EventBus3
DBFlow
AndroidAnnotation
Use posture
1. In the android project, create a Module of java and write a class that inherits AbstractProcessor
@ AutoService (Processor.class) / / javax.annotation.processing.IProcessor @ SupportedSourceVersion (SourceVersion.RELEASE_7) / / java @ SupportedAnnotationTypes ({/ / Annotation processor supported annotation types "com.annotation.SingleDelegate", "com.annotation.MultiDelegate"}) public class AnnotationProcessor extends AbstractProcessor {public static final String PACKAGE = "com.poet.delegate"; public static final String CLASS_DESC = "From poet compiler"; public Filer filer; / / File-related helper class public Elements elements / / element-related auxiliary class public Messager messager; / / log-related auxiliary class public Types types; @ Override public boolean process (Set