记录一些常用的Adb命令,以及一些常见的错误。

常用命令

1、查看栈顶Activity :

adb shell dumpsys activity 

adb shell dumpsys activity | grep mResumed

2、通过命令行打开Activity界面 :

adb shell am start -n pkgname/pkgname.activity 

例如:

adb shell am start -n com.my.demo/.activity.MainActivity 
adb shell am start -n com.my.demo/com.my.demo.error.ErrorActivity

3、adb启动service:

adb shell
am startservice -n {包(package)名}/{包名}.{服务(service)名称}
如:启动自己应用中一个service
am startservice -n com.android.traffic/com.android.traffic.maniservice

4、adb发送broadcast:

adb shell
am broadcast -a <广播动作>
如:发送一个网络变化的广播
am broadcast -a android.net.conn.CONNECTIVITY_CHANGE

5、模拟器真机同时存在的情况下,安装Apk:

adb -d install {apkpath}

6、查看App启动消耗时间

You can also measure the time to initial display by running your app with the ADB Shell Activity Manager command. Here’s an example:

adb [-d|-e|-s <serialNumber>] shell am start -S -W

com.example.app/.MainActivity

-c android.intent.category.LAUNCHER

-a android.intent.action.MAIN

The Displayed metric appears in the logcat output as before. Your terminal window should also display the following:

Starting: Intent

Activity: com.example.app/.MainActivity

ThisTime: 2044

TotalTime: 2044

WaitTime: 2054

Complete

The -c and -a arguments are optional and let you specify category and action for the intent.

7、查看进程启动

过滤关键字: start proc

8、过滤Android异常

adb logcat | grep AndroidRuntime

Adb Error相关

1、使用Genymotion遇到错误:

adb server version (32) doesn't match this client (36); killing...

反反复复的 adb kill-server –> start-server,还是同样的错误。

原因:genymotion的adb设置。

解决方案如下:

pic

Adb相关资料

Adb官网教程:https://developer.android.com/studio/command-line/adb.html#shellcommands

官网性能优化教程:https://developer.android.com/topic/performance/launch-time.html

《Android ADB命令?这一次我再也不死记了!》:http://mp.weixin.qq.com/s/fWaa1rutwfoIIrje8RfWBw

adb logcat 命令行用法:http://blog.csdn.net/tumuzhuanjia/article/details/39555445


分享到