工作中,想debug下自定义的AbstractProcessor,那么如何使用Android Studio和gradle来调试呢
- 在代码中对init()方法或process()等方法设置代码断点!
- 设置gradle daemon端口和JVM参数。把下面两行加入到你的gradle.properties文件。
org.gradle.daemon=true
org.gradle.jvmargs=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
- 在命令行中运行gradle daemon来启动守护线程。
gradle --daemon
- 在Android Studio建立Remote Debugger并运行它。
image
image
在这里使用默认设置,IP:localhost,端口:5005。一旦你完成并运行它,那它就会连接到daemon线程中了。
- 用gradle命令来运行构建。
gradle clean assembleDebug
既然我们已经启动了守护线程,Remote Debugger将触发断点并挂起构建运行。
Done!