Gradle is a scripting tool. In the process of development, the most painful thing is to “debug”. Most of the time, we use Log to debug.

Logging

Logging is a Logging tool provided by Gradle. It is very simple to use and we can encapsulate it.

fun log(log: String) {
    Logging.getLogger(MyPlugin::class.java).lifecycle(log)
}
Copy the code

GetLogger provides an example of Logging, which is similar to Android’s native Log, with debug, INFO, error, and other Log levels. You can call it as needed.

Breakpoint debugging

The Gradle plugin can’t debug breakpoints like normal code. You need to use Android Studio’s Remote debugging function.

First, you need to create a Remote debugger in Android Studio. On the run TAB, click “Edit Configuration”, then click “+” to add a new debug type, select Remote, and name it “plugin_debug” (or any other name). As shown below.

Next, under the current project terminal, enter the following command:

➜  ASMTest git:(master) ./gradlew assembleDebug -Dorg.gradle.debug=true --no-daemon
Copy the code

With this command, you can make Gradle wait for the Plugin to Attach to the Remote while compiling.

Finally, select the “plugin_DEBUG” option you just created on the run TAB, and then click the Debug button to execute the command and wait for the breakpoint to hit.

I’d like to recommend my website Xuyisheng. Top/focus on Android-Kotlin-flutter. Welcome to visit