I study annotation processor. How to debug? How can I run through the process method, as in the debug?
1 answer
In principle, our article and it suits me. But there is something very complicated. If someone finds an easier explanation, write.
Remember that annotation processing occurs during the compilation phase. However, the normal debugging uses the java debugger (jdb), which works once the code is compiled and generated. So we need to debug the compile phase. How can we do this? Build tool we are using. In the case of the GRADLE_OPTS environment variable, we can set the options -Dorg.gradle.debug=true . This option enables the remote control to continue the process, and will suspend the process until it is attached (see docs for more info). With Maven we can do this with mvnDebug.
We aim to debug is usually named compileDebugJavaWithJavac . If you use flavors, you like compileFlavorDebugJavaWithJavac . It is a time to get a clean run. Also, it’s not necessary to work. The following:
./gradlew --no-daemon -Dorg.gradle.debug=true :app:clean :app:compileDebugJavaWithJavac Next we need to connect the IDE to the debugger. To do this, we need to create a Run / Debug Configuration for remote debugging. We first click on the menu Run, then Edit Configurations .... Where it says Remote click in the add icon. Choose the port for the configuration of 5005. Then just click OK.
Then you can make a task, which will start running. Afterwards, stopping in and out.