background

    @Override
    public synchronized void init(ProcessingEnvironment processingEnv) {
        
    public boolean process(Set<? extends TypeElement> set, RoundEnvironment roundEnv) {
    
Copy the code

APT code fixed template what is ProcessingEnvironment? What is TypeElement? What is RoundEnvironment?

The solution

Debug the code to see what values are inside the object in the debug window. The steps are as follows:

1. Open APT debugging mode

org.gradle.jvmargs=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
-Dorg.gradle.debug=true
Copy the code

2. Create an APT debug type

How to create www.jianshu.com/p/4fef2ad51 according to here…

3. The debugging

  1. Make sure APT code is not generated by executing clean
  2. Connected to the target VM, address: ‘localhost:5005’, transport: ‘the socket.

conclusion

Familiarize yourself with object meanings while debugging, and then piece the code together. Note:

  1. Be sure to turn the debug switch off after debugging, i.e. change the global gradle.properties back. Otherwise, normal development will be affected.
  2. Debugging if an Error occurs when the Error running ‘Remote Debugger’ : Unable to open the Debugger port (localhost: 5005) : java.net.ConnectException. Kill or restart the IDE for port 5005.
  3. Do not debug multiple projects at the same time.