63

启用Gradle远程调试

 5 years ago
source link: http://www.10tiao.com/html/272/201807/2666454291/1.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

编写gradle对象插件的实现方式有3种:

  1. 直接写在build.gradle中,这种方式简单省事,比较适合比较小的插件编写

  2. 在项目根目录下建立buildSrc目录

  3. 建立一个独立的项目工程,以jar包的形式提供依赖

在编写对象插件的过程中很多都需要进行调试,本文就介绍一下如何启动gradle远程调试。

启动远程调用

首先点击Run-> Edit Configuration

Edit Configuration.png

然后点击+号,Add New Configutation,我们选择Remote


Add New Configutation.png

我们新建一个命名为apt-debug的remote,并且复制Command Line对应下的这段语句,当然了,我们在这里实际上也可以更改端口号的。也可以用当前默认的端口号5005。

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005

Remote.png

然后点击Android Studio右侧的gradle选项


gradle.png

假如我们要选择app模块进行调试,可以在build下的assembleRelease任何下,右击,会有一个弹出窗口。

assembleRelease.png

我们点击Create 选项。会有如下窗口:

Create.png

在VM options下填入我们刚才复制的信息,要注意的是把suspend对应的值改为y

VM options.png

然后会生成一个Run Condigurations的Task group。


Run Condigurations.png

双击这个assembleRelease的调试任务,这个这个任务就会被挂起,等待着调式


等待着调式.png

然后我们选择apt-debug,在点击右侧的debug按钮,就可以开始调试了。


点击右侧的debug按钮.png

使用命令行

debug 模式运行 gradle 脚本

gradle :app:clean -Dorg.gradle.debug=true  --no-daemon

声明环境变量 GRADLE_OPTS

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

attach Debugger

记住,如果想继续调试,就以Debug方式再次运行我们在Run Configuration下生成的assembleDebug或者assembleRelease。

再次debug.png


                        喜欢 就关注吧,欢迎投稿!



作者:sososeen09
链接:https://www.jianshu.com/p/b86330a877db
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。



About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK