Lore
Lore

Reputation: 1968

Debugging gradle files in Android Studio

I have read in other answers that in IntelliJ IDEA is possible to debug gradle files.

Can I do the same thing on Android Studio? And how?

EDIT: my question is not duplicate because it regards not IntelliJ but only Android Studio.

Upvotes: 12

Views: 6419

Answers (1)

Rodrigo Queiroz
Rodrigo Queiroz

Reputation: 2864

In order to debug Gradle, we have to create a new remote configuration in Android Studio.

1. Open "EditRun/Debug configurations" dialog:

Edit configuration dialog

Don't forget to add your breakpoint in the build.gradle file.

Add gradle break point

2. Once in "Run/Debug Configuration" click on the + icon to add a new configuration and then select Remote:

Add remote configuration

  • You will be presented with the "Remote" configuration options.
  • (Optional) rename configuration from "Unnamed" to whatever name you desire.
  • Then click "OK"

Rename remote configuration

As you can see on the above image I've chosen "Gradle Remote Debug".

3. Now select your "Remote" configuration in the "EditRun/Debug configurations" dialog and go to "Terminal" in Android Studio and type the following command:

./gradlew help -Dorg.gradle.debug=true --no-daemon

The above command option can be anything "help, tasks, etc." the only important attribute is -Dorg.gradle.debug=true --no-daemon and having the "Remote" configuration setup.

After inputting the above command hit "Enter" and you'll see that the command will start the Daemon and will be listening for the remote debugger as illustrated on the following picture.

Start Daemon

4. Now all that is left to do is to attach the debugger by clicking on the "Debug" icon in Android Studio.

Debug icon

Then if you haven't forgotten to set your breakpoint you'll see that Gradle will be executed and will stop at the breakpoint.

Run to breakpoint

References: Debugguing Build Logic

Upvotes: 29

Related Questions