Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging Gradle build files in Intellij / Android Studio

I am sometimes running into obscure problems with Gradle. Sometimes it helps if i am reading the source files or adding println statements to figure out what i can do and what the state is.

But i would really like to just place a breakpoint and list the internal state of variables. is that possible using Android Studio or IntelliJ ?

I would also love to ctrl-click to the DSL keywords so i can get some context.

Just placing a breakpoint and clicking "debug" from the list of gradle tasks does not work, it just runs the tasks without stopping.

like image 864
Andreas Petersson Avatar asked Feb 25 '14 14:02

Andreas Petersson


People also ask

Where is build Gradle file in Android Studio?

The top-level build.gradle file, located in the root project directory, defines dependencies that apply to all modules in your project. By default, the top-level build file uses the plugins block to define the Gradle dependencies that are common to all modules in the project.


2 Answers

You can't debug Gradle files. We may someday implement this, as it would obviously be a great thing, but it's a long ways off. We're in the process of adding more intelligence about syntax highlighting and analysis of build files. Well, actually, JetBrains is adding it to IntelliJ and we're picking it up. This will get better over the coming weeks and months.

like image 165
Scott Barta Avatar answered Oct 19 '22 21:10

Scott Barta


Original source

1. Create a debugger

  • Run -> Edit Configurations

enter image description here

  • Add New Configuration

enter image description here

  • Add Remote configuration

enter image description here

2. Open debug mode

$ export GRADLE_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"

3. Start debugger

$ ./gradlew someTask -Dorg.gradle.daemon=false #!important, disable daemon mode

4. Attach debugger

  • Set breakpoints

enter image description here

  • Start debug

enter image description here

5. Disable debug mode

$ unset GRADLE_OPTS
like image 21
Víctor Albertos Avatar answered Oct 19 '22 20:10

Víctor Albertos