介绍一点安卓开发中常用的adb命令。
1.安卓开发中常用的adb命令
- 打印手机显示的当前页面
//首先进入shell命令行模式
adb shell
//显示当前Activity信息
logcat -s ActivityManager
- 安装APP
adb install -r AndroidTest.apk
这里添加 -r 参数可以在不卸载旧版的情况下,进行版本升级。
- 卸载APP
adb uninstall com.example.androidtest
- 启动Activity
adb shell am start com.example.androidtest/.MainActivity
or
adb shell am start com.example.androidtest/com.example.androidtest.MainActivity
这里有一个要求:要启动的Activity在Manifest中有:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
或
android:exported="true"
- 使用默认浏览器打开一个URL
adb shell am start -a android.intent.action.VIEW -d http://www.baidu.com
- 关闭/打开手机屏幕
adb shell input keyevent 26
- 清除APP数据
adb shell pm clear com.example.androidtest
- 打印日志信息
adb logcat
执行上面的命令会打印N多的信息,下面对信息进行一下筛选
- 通过tag过滤
输出指定tag(xxx或 (xxx和yyy))的内容
adb logcat -s xxx
or
adb logcat -s xxx yyy
- 通过优先级过滤
打印warn及其以上的日志信息:
adb logcat *:W
安卓中日志信息中优先级情况:
V - Verbose (lowest priority)
D - Debug
I - Info
W - Warning
E - Error
F - Fatal
S - Silent (highest priority, on which nothing is ever printed)
- 通过tag&&优先级进行过滤
adb logcat -s xxx:W
or
adb logcat -s xxx:W yyy:W
- 清空日志
adb logcat -c
翻译地址:
http://www.growingwiththeweb.com/2014/01/handy-adb-commands-for-android.html
- 录制视频
adb shell screenrecord /sdcard/movie.mp4
可以按Ctrl+C停止。
第三方软件占用adb端口问题
这种情况,经常发生在电脑空闲时间较长的时候。
1.在Windows的Path中配置上adb的路径(PS:这样就不用每一次调用adb命令,都必须转到adb.exe文件所在的目录了)
1.下午如果手机出现连接不上电脑的情况,win+R,打开控制台,输入
adb kill-server
adb start-server adb 可能就连接上了(不过一般都是老样子,adb restart-server 这个命令不是很好使),如果出现下图的情况,基本上就是越俎代庖了。
2.此时很有可能,是第三方软件,占用了adb需要使用的端口。使用
adb nodaemon server
在确认一下。
3.执行一下命令,看一下那个贱人是谁(只能看到其PID)
netstat -ano | findstr “5037”
4.到任务管理器
5.结束掉该进程,然后再命令行执行:
adb start-server
这时一般就好了。