安装、卸载、启动、杀应用、清除数据的命令
- 安装,卸载APK命令
adb install xxx.apk
adb uninstall com.xxx.xxx
- 清除APP数据
adb shell pm clear com.xxx.xxx
- 启动APP命令
adb shell am start -n com.xxx.xxx/com.xxx.xxx.xxxActivity
测试App启动速度的命令
- -W:等待app启动完成
- -R <COUNT>:重复启动Activity COUNT次
- -S:启动activity之前,先调用forceStopPackage()方法强制停止app.
adb shell am start -W -S -R 10 包名/类名
- 杀应用的命令
adb shell am force-stop com.xxx.xxx
查看当前打开的页面
adb shell "dumpsys activity | grep mFoc"
// 或者
adb shell dumpsys activity top | grep ACTIVITY
mFocusedActivity: ActivityRecord{fa6bd0b u0 com.xtc.i3launcher/.module.home.view.activity.HomeActivity t671}
mFocusedStack=ActivityStack{64d8b2f stackId=0, 1 tasks} mLastFocusedStack=ActivityStack{64d8b2f stackId=0, 1 tasks}
屏幕相关命令
- 设备分辨率
adb shell wm size
Physical size: 320x360
- 设备屏幕信息
adb shell dumpsys window displays
WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)
Display: mDisplayId=0
init=320x360 320dpi cur=320x360 app=320x360 rng=320x272-360x312
deferred=false layoutNeeded=false
- 查看连接的设备
adb devices
List of devices attached
2acde337 device
应用信息相关命令
- 查看应用的信息
adb shell dumpsys package com.xxx.xxx
Activity Resolver Table:
Non-Data Actions:
android.intent.action.MAIN:
8d2618a com.xx.xx/.MainActivity filter 6a8d564
Action: "android.intent.action.MAIN"
Category: "android.intent.category.LAUNCHER"
AutoVerify=false
607c3fb com.xx.xx/com.squareup.leakcanary.internal.DisplayLeakActivity filter 63f83cd
Action: "android.intent.action.MAIN"
Category: "android.intent.category.LAUNCHER"
AutoVerify=false
- 查看设备安装的应用列表
adb shell pm list packages
package:com.android.providers.telephony
package:com.android.providers.media
package:com.android.mms.service
package:com.android.providers.downloads
...
- 查看分配内存
adb shell "getprop | grep heap"
[dalvik.vm.heapgrowthlimit]: [96m]
[dalvik.vm.heapmaxfree]: [8m]
[dalvik.vm.heapminfree]: [512k]
[dalvik.vm.heapsize]: [256m]
[dalvik.vm.heapstartsize]: [8m]
[dalvik.vm.heaptargetutilization]: [0.75]
- 安装后导出APK文件
先使用adb shell pm path com.xxx.xxx找到路径
package:/data/app/com.xxx.xxx-1/base.apk
再使用adb pull 上面的path导出APK
adb pull /data/app/com.xxx.xxx-1/base.apk
/data/app/com.xxx.xxx-1/base.apk: 1 file pulled. 10.9 MB/s (5335113 bytes in 0.465s)
- GC
adb shell pkill -l 10 PACKAGE_NAME
- dump java heap
adb shell am dumpheap PACKAGE_NAME OUT_PATH
- hprof文件格式转换后可以使用MAT工具查看
hprof-conv -z 文件名 new文件名
- 查看应用内存信息
adb shell dumpsys meminfo com.xxx.xxx
Applications Memory Usage (in Kilobytes):
Uptime: 26508885 Realtime: 85388702
** MEMINFO in pid 13264 [com.xxx.xxx] **
Pss Private Private Swap Heap Heap Heap
Total Dirty Clean Dirty Size Alloc Free
------ ------ ------ ------ ------ ------ ------
Native Heap 6237 6192 20 8392 19072 14273 4798
Dalvik Heap 14287 14228 40 1988 14613 10960 3653
Dalvik Other 3191 3172 12 16
Stack 648 648 0 192
Ashmem 9 4 0 0
Gfx dev 9606 9156 0 0
Other dev 8 0 4 0
.so mmap 4046 332 2288 2016
.jar mmap 4 0 4 0
.apk mmap 91 0 0 0
.ttf mmap 60 0 28 0
.dex mmap 1808 0 1808 4
.oat mmap 4304 0 1748 60
.art mmap 2166 1220 96 208
Other mmap 519 4 476 4
Unknown 703 692 0 444
TOTAL 47687 35648 6524 13324 33685 25233 8451
- 设备所有应用占用内存信息
adb shell dumpsys meminfo
- 设备内存信息
adb shell cat /proc/meminfo
>>
MemTotal: 411908 kB
MemFree: 7356 kB
MemAvailable: 154508 kB
Buffers: 15508 kB
Cached: 135236 kB
SwapCached: 11776 kB
Active: 132336 kB
Inactive: 130768 kB
Active(anon): 56520 kB
Inactive(anon): 57500 kB
Active(file): 75816 kB
Inactive(file): 73268 kB
Unevictable: 256 kB
Mlocked: 256 kB
SwapTotal: 338936 kB
SwapFree: 229736 kB
Dirty: 4 kB
Writeback: 0 kB
AnonPages: 112148 kB
Mapped: 79380 kB
Shmem: 1660 kB
Slab: 40528 kB
SReclaimable: 11400 kB
SUnreclaim: 29128 kB
KernelStack: 7528 kB
PageTables: 10664 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 544888 kB
Committed_AS: 10878244 kB
VmallocTotal: 499712 kB
VmallocUsed: 59448 kB
VmallocChunk: 336724 kB