Git Product home page Git Product logo

apkdebugconnection's Introduction

####ApkDebugConnection

一条命令搞定本地端口映射到设备中某个运行的apk的jdwp对应的端口。

####前言 假设我们要debug的apk为 com.hackooo.example.apk , apk的packageName为com.hackooo.example , apk启动的Activity为com.hackooo.example.biz.SplashActivity.

在debug一些apk的时候,是不是已经厌倦了以下这些重复的步骤:

  1. adb shell am start -D -S -W com.hackooo.example/.biz.SplashActivity
  2. 然后等待10s左右,告诉你已经超时了
  3. 接着 adb shell ps | grep com.hackooo.example 查看对应的进程的pid
  4. adb forward tcp:8800 jdwp:{pid,上一步得到的pid}

这几条命令虽然不是很复杂,但敲起来也得十几二十秒,关键是,在debug的时候,要一直重复,非常麻烦。 好了,写个脚本搞定这些无聊的步骤。

####如何使用 首先修改配置文件 env.conf

[config]
;adb 路径,修改为你自己的adb的路径
adb = ~/Library/Android/sdk/platform-tools/adb
;aapt 路径,修改为你自己的aapt的路径
aapt = ~/Library/Android/sdk/build-tools/23.0.2/aapt
;设备中apk运行的进程映射到本地的端口,这个随意定,不要与其它端口冲突即可。
targetport = 8800

然后执行 ./adbConnect.py {your apk} (前提是你已经安装了这个apk)

对应到上面的例子,就是./adbConnect.py com.hackooo.example.apk

接着就可以用你的Android Studio 连接端口痛快debug啦!

####脚本的基本思路 其实跟手动敲是一样的,只不过在启动应用的时候把超时改短一点,不用等太久。

  1. 拿到apk后,用aapt解析出apk的packageName和启动的Activity
  2. 执行adb shell am start -D -S -W {activity} , 并加上3s的超时,不用等10s
  3. adb shell ps | grep {packageName} 拿到进程的pid
  4. adb forward tcp:{targetport} jdwp:{pid}

有任何问题欢迎交流。

apkdebugconnection's People

Contributors

hackoooo avatar

Watchers

James Cloos avatar bluce avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.