HomeAbout MeContact Me

How to debug an Annotation Processor in Android Studio

By Emanuele Papa
Published in Development
July 05, 2020
1 min read
How to debug an Annotation Processor in Android Studio

Writing an Annotation Processor in Java/Kotlin is a very interesting task and debugging comes very handy, but unfortunately it seems not so easy to start a debug session.

The following information are valid for Android Studio 3.6.3 and Kotlin 1.3.71. Gradle is the build tool used for the project.

First thing to do is setup a new Run/Debug Configuration in Android Studio:

  • Choose Run from the main menu
  • Choose Edit Configurations
  • Now click on the + symbol in the top left corner to add a new Configuration
  • Choose Remote from the list
  • Give it a friendly name (e.g. AnnotationProcessorDebugger)

Setup your breakpoints wherever you need them and then run this command from the terminal:

./gradlew --no-daemon -Dorg.gradle.debug=true :APP_MODULE_NAME:clean :APP_MODULE_NAME:compileDebugJavaWithJavac

Replace APP_MODULE_NAME with the name of the module having annotations which you want to debug. You will see the process will start and suddenly stop on > Starting Daemon waiting for you to do something.

Now, click on the Debug icon in the Toolbar (having selected the previously created AnnotationProcessorDebugger configuration) and the debugger will hit your breakpoints!

Additional info

The clean task seems to be necessary.

Unfortunately, sometimes these steps are not enough, or simply don’t work, the debugger won’t hit your breakpoints. I see somebody else solved the issue after adding the following line to their gradle.properties file.

kapt.use.worker.api=true

Tags

#development#android#java#kotlin
Previous Article
Add UEFI support to your AMD HD7970 to use Secure Boot
Emanuele Papa

Emanuele Papa

Android Developer

Topics

Android
AWS
Development
Info
Linux
Modding
Smart Home
Windows

Related Posts

Flutter Padding widgets generator with Paddinger
May 16, 2021
1 min
Copyright © Emanuele Papa 2021, All Rights Reserved.

Quick Links

HomeAbout MeContact MeRSS Feed

Social Media