Android开发常用命令

Posted by 夏敏的博客 on July 5, 2016
  • 搜索类

find 目录 -name 名字


grep命令 -r代表递归
grep -r “内容”
grep -rE ‘内容a|内容b’ 有内容a或者内容b的
grep -r 内容a | grep 内容b 既有a也要有b

将文件中XXX替换成YYY
sed -i ‘s/XXX/YYY/g’ grep XXX . -rl

locate命令

  1. locate的速度比find快,因为它并不是真的查找文件,而是查数据库
  2. locate的查找并不是实时的,而是以数据库的更新为准,一般是系统自己维护
  3. 升级数据库命令:locate – u
  • 查看进程类

ps 查看进程
ps -t 进程号或者grep 命令

  • Android源码编译

source build/envsetup.sh;
lunch
make -j8

  • Android干掉进程类

普通进程,activity manager就能干掉
adb shell am force-stop com.avatar.settings

adb shell ps | grep com.avatar.dialog
adb shell kill 3349

我们还可以直接用ps -t 加进程号 查看该进程的详细情况及其开的子线程个数

> root@rk3288:/ # ps -t 3308                                            
> USER     PID   PPID  VSIZE  RSS     WCHAN    PC         NAME system   
> 3308  168   957444 102596 ffffffff 4004e754 S com.avatar.dialog system
> 3312  3308  957444 102596 c007ef6c 4004e920 S GC system    3313  3308
> 957444 102596 c004622c 4004e188 S Signal Catcher system    3314  3308
> 957444 102596 c0115d44 4004d6f0 S JDWP system    3315  3308  957444
> 102596 c007ef6c 4004e920 S Compiler system    3316  3308  957444
> 102596 c007ef6c 4004e920 S ReferenceQueueD system    3317  3308
> 957444 102596 c007ef6c 4004e920 S FinalizerDaemon system    3318  3308
> 957444 102596 c007ef6c 4004e920 S FinalizerWatchd system    3319  3308
> 957444 102596 c05a7d64 4004d5a4 S Binder_1 system    3320  3308
> 957444 102596 c05a7d64 4004d5a4 S Binder_2 system    3321  3308
> 957444 102596 c0140070 4004e754 S Notify system    3322  3308  957444
> 102596 c0140070 4004e754 S WifiManager system    3324  3308  957444
> 102596 c007ef6c 4004e920 S m.avatar.dialog system    3325  3308
> 957444 102596 c007ef6c 4004e920 S m.avatar.dialog system    3326  3308
> 957444 102596 c007ef6c 4004e920 S m.avatar.dialog system    3327  3308
> 957444 102596 c007ef6c 4004e920 S m.avatar.dialog system    3328  3308
> 957444 102596 c007ef6c 4004e920 S m.avatar.dialog system    3329  3308
> 957444 102596 c007ef6c 4004e920 S m.avatar.dialog system    3336  3308
> 957444 102596 c007ef6c 4004e920 S AsyncTask #1 system    3337  3308
> 957444 102596 c007ef6c 4004e920 S AsyncTask #2 system    3339  3308
> 957444 102596 c007ef6c 4004e920 S CMEM Purge system    3340  3308
> 957444 102596 bf011f64 4004d2e0 S mali-event-hnd system    3341  3308
> 957444 102596 c007ef6c 4004e920 S mali-utility-wo system    3342  3308
> 957444 102596 c007ef6c 4004e920 S mali-utility-wo system    3343  3308
> 957444 102596 c007ef6c 4004e920 S mali-utility-wo system    3344  3308
> 957444 102596 c007ef6c 4004e920 S mali-utility-wo system    3345  3308
> 957444 102596 c007ef6c 4004e920 S mali-renderer system    3346  3308
> 957444 102596 c007ef6c 4004e920 S AsyncTask #3 system    3347  3308
> 957444 102596 c05a7d64 4004d5a4 S Binder_3 system    3352  3308
> 957444 102596 c007ef6c 4004e920 S m.avatar.dialog system    3355  3308
> 957444 102596 c007ef6c 4004e920 S m.avatar.dialog system    3367  3308
> 957444 102596 c007ef6c 4004e920 S m.avatar.dialog
  • 强启应用命令

adb shell am start -a android.intent.action.MAIN -n com.avatar.settings/.Settings

  • 产生5000次monkey触摸事件

adb shell monkey -v 5000
adb shell monkey -p com.avatar.settings -s 500 -v 10000

  • 查看系统占用率最高的10个线程

    top -m 10 -t

  • 使用dumpsys查看系统信息

    dumpsys cpuinfo 查看CPU占用率情况

  • 查看当前顶层Activity

    adb shell dumpsys activity | grep -e Resumed -e Focused adb shell dumpsys activity -p packagename a | less

  • adb录屏幕

adb shell screenrecord –size 480x320 /sdcard/test2.mp4
adb shell screenrecord /sdcard/test.mp4
adb pull /sdcard/test.mp4

  • adb模拟返回键

adb shell input keyevent 4

  • 替换文本

sed -i ‘s/Runing/Running/g’ grep Runing . -rl sed -i ‘s/原/目标/g’ grep 原 . -rl

  • Ubuntu 在ADB调试手机时报 error: insufficient permissions for device

adb devices

查看名称和id

lsusb

Bus 001 Device 016: ID 2a45:0c02 Meizu Corp. MX Phone (MTP & ADB)

cd /etc/udev/rules.d/ sudo vim 51-android.rules 写入

SUBSYSTEM=="usb", ATTRS{idVendor}=="2a45",
ATTRS{idProduct}=="0c02",MODE="0666"

接着拔出手机重插即可。

  • 列出目标设备中已安装的应用程序包

    adb shell pm list packages
    adb shell pm path packagename

  • 查看PackageManager的disbale应用

    su 获取管理员权限
    pm enable com.android.cellbroadcastreceiver
    pm list

  • 卸载应用

    adb uninstall 包名

  • 在线Debug应用

    LOCAL_PROGUARD_ENABLED := full

  • 启动应用时候debug应用

    adb shell am set-debug-app -w –persistent com.android.cts.documentclient
    adb shell am clear-debug-app // 清空

  • 往SettingsProvider写值

    adb shell settings put global key value

  • 掉帧测试

    adb shell dumpsys gfxinfo com.android.settings reset
    adb shell dumpsys gfxinfo com.android.settings
    看 Janky frames: 360 (21.53%)

  • 列出当前手机几个用户

    adb shell pm list users

  • 重置手机-自己的手机小心使用这个命令

    adb shell am broadcast -a “android.intent.action.FACTORY_RESET” -p android –ez format_sdcard true

作者:Anderson大码渣,欢迎关注我的简书: Anderson大码渣