简体   繁体   中英

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.

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.

Original source

1. Create a debugger

  • Run -> Edit Configurations

在此处输入图片说明

  • Add New Configuration

在此处输入图片说明

  • Add Remote configuration

在此处输入图片说明

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

在此处输入图片说明

  • Start debug

在此处输入图片说明

5. Disable debug mode

$ unset GRADLE_OPTS

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM