Adb和各种android相关开发实用命令收集
Adb各种实用命令收集
若连接多台使用adb -s操作。 windows下使用findstr,linux和mac下使用grep。
通过无线连接ADB:
通过配对码连接ADB:
以root方式执行shell命令:
Read-only file system
时以可读写方式执行:
如果结果太长可以保存到文件中,如:
>
新建或覆盖文件保存:adb shell pm list packages > installed_package.txt
>>
往文件中追加结果: adb shell pm list packages >> installed_package.txt
adb kill-server
adb start-server
adb devices
adb shell ifconfig wlan0
adb push /Users/caochang/apk/BBox.apk /sdcard/xbd/BBox.apk
adb pull /sdcard/xbd/BBox.apk /Users/caochang/apk/BBox.apk
adb shell getprop > info.txt
adb shell dumpsys iphonesubinfo
adb shell getprop ro.product.brand
adb shell getprop ro.product.model
adb shell getprop ro.build.version.sdk
adb shell getprop ro.build.version.release
adb shell wm size
adb shell wm size 1080*1920
adb shell wm density
adb shell wm density 480
adb shell getprop ro.product.cpu.abilist(Android5.0系统之后)
adb shell getprop ro.product.cpu.abi(Android5.0系统之前)
adb shell cat /sys/class/net/eth0/address(网卡一)
adb shell cat /sys/class/net/wlan0/address(无线网卡)
adb shell settings get secure android_id
adb shell content query --uri content://settings/secure/android_id --projection value
adb shell system/etc/media_codecs.xml
adb shell cat /etc/media_codecs.xml | grep -i "hevc"(查看是否支持h265)
获取开发者选项值
adb shell settings get global development_settings_enabled
打开开发者选项
adb shell settings put global development_settings_enabled 1
关闭开发者选项
adb shell settings put global development_settings_enabled 0
获取adb调试值
adb shell settings get global adb_enabled
打开adb调试
adb shell settings put global adb_enabled 1
关闭adb调试
adb shell settings put global adb_enabled 0
adb shell settings get system screen_off_timeout
adb shell settings put system screen_off_timeout 60000
adb shell settings get secure sms_default_application
adb shell settings put secure sms_default_application com.carlos.sms
adb shell "dumpsys window policy | grep mScreenOnFully"
adb shell dumpsys power | findstr "Display Power:state="
adb shell cat /system/build.prop
heapgrowthlimit
:普通应用内存限制,对应ActivityManager.getMemoryClass()
方法获取的值
heapsize
:manifest
中设置了largeHeap=true
之后,可以使用的最大内存值,对应ActivityManager.getLargeMemoryClass()
方法获取的值
adb shell getprop persist.sys.dalvik.vm.lib
若值为libdvm.so则为dalvik,libart.so则为art
Android4.4目录下,相关路径data/data/com.android.providers.settings/databases/settings.db
,可以打开数据库查看
Android7.x目录下,相关路径data/system/users/0
,路径下settings_secure.xml
、settings_system.xml
、settings_global.xml
文件
获取值
adb shell settings get system [key]
adb shell settings get global [key]
adb shell settings get secure [key]
设置值
adb shell settings put secure [key] [value]
...
如,获取定义按转为长按之前的默认持续时间(毫秒):adb shell settings get secure long_press_timeout
adb shell setprop persist.sys.theme ""
adb shell am start
-W: wait for launch to complete
-S: force stop the target app before starting the activity
例adb shell am start -W com.UCMobile/com.uc.browser.InnerUCMobile
在AS中可过滤displayed
输出的启动日志
adb shell dumpsys cpuinfo| find "com.sec.android.app.launcher"
adb shell "dumpsys meminfo | grep com.carlos.bbox
adb shell "ps | grep com.aspire.agent" 得到结果第二列的值为pid
adb shell cat /proc/6094/status
adb shell "cat /proc/uid_stat/10189/tcp_snd"
adb shell "cat /proc/uid_stat/11110/tcp_rcv"
adb shell dumpsys dropbox --print >>crashlog_$(date +%Y%m%d%H%M).txt
adb shell cat /proc/meminfo
adb shell kill -9 6094
adb shell pm list packages [-com.carlos.bbox]
adb shell pm clear com.carlos.bbox
adb uninstall com.carlos.bbox
adb shell pm uninstall -k --user 0 com.carlos.test
adb install (-r强制安装) /Users/caochang/apk/BBox.apk
adb shell pm install (-r) /sdcard/xbd/BBox.apk
adb install-multiple -r /Users/caochang/apk/BBox.apk
adb shell am broadcast -a com.carlos.bbox -e port 8888
adb shell am startservice com.carlos.bbox/com.carlos.bbox.MyService
adb shell am start -n com.carlos.bbox/.MainActivity
adb shell am start -n com.test.app/com.test.TestActivity -d test://com.test.app/test?testId=13
启动带参数:
-a action;activity对应的action;
--es key stringValue; 传递 String 参数;
--ez key booleanValue; 传递 Boolean 参数;
--ei key intValue; 传递 int 参数;
--el key longValue; 传递 long 参数;
--ef key floatValue; 传递 float 参数;
adb shell am froce-stop com.carlos.bbox
adb shell dumpsys window | grep mCurrentFocus
adb shell dumpsys activity top
adb sehll pm list packages | grep "com.carlos.test"
adb shell pm path com.carlos.grabredenvelope
adb pull /data/app/com.example.carlos.myapplication--y9EFnP-__j34XhQxIwXvA==/base.apk(找到的apk路径)
adb shell dumpsys activity top > info.txt
adb shell monkey -p com.codemao.dan -v 1000
adb shell monkey -p com.codemao.dan --throttle 1000 20
adb shell input tap 250 250
adb shell input text hello world
adb shell screencap -p /sdcard/a.png
adb shell screenrecord /sdcard/test.mp4
adb logcat -v thradtime > log.txt
adb logcat -c
adb logcat -g
adb logcat -G 2MB
adb shell am start -a android.intent.action.VIEW -d "https://www.baidu.com"
adb shell tcpdump -i any -p -s 0 -w /sdcard/11.pcap
Ipv4封堵:
iptables -I INPUT -s 192.168.1.138 -j DROP
Ipv4解除:
iptables -I INPUT -s 192.168.1.138 -j ACCEPT
Ipv6封堵:
ip6tables -I INPUT -s 1050:0000:0000:0000:0005:0600:300c:326b -j DROP
Ipv6解除:
ip6tables -I INPUT -s 1050:0000:0000:0000:0005:0600:300c:326b -j ACCEPT
Charles抓包,针对Lancher未提供设置网络代理和打开浏览器功能,使用adb来打开原生设置网络代理安装证书
adb shell am start -a android.settings.SETTINGS
adb shell am start com.android.settings/com.android.settings.Settings
adb shell input text 172.17.5.166
adb shell am start com.android.browser/com.android.browser.BrowserActivity
chls.pro/ssl
安装证书adb shell input text chls.pro/ssl
找到了更加快捷的做法,直接adb设置代理,如:
adb shell settings put global http_proxy 127.0.0.1:8888
adb清除代理:
adb shell settings put global http_proxy :0
模拟按键上下
adb shell input keyevent KEYCODE_DPAD_UP
adb shell input keyevent KEYCODE_DPAD_DOWN
adb shell setprop debug.layout true
adb shell setprop debug.layout false
立即生效
adb shell service call activity 1599295570
adb shell service call window 3
返回值是:Result: Parcel(00000000 00000000 '........')" 说明View Server处于关闭状态
返回值是:Result: Parcel(00000000 00000001 '........')" 说明View Server处于开启状态
adb shell service call window 1 i32 4939
adb shell service call window 2 i32 4939
*#06#
首先进入操作系统的拨号界面,输入指令码即可快速进入Android的工程测试模式。
常见机型进入工程模式的指令码是:
adb jdwp
Source Insight
阅读源码在某些手机上进入到package文件夹下执行ls命令会出现以下问题,参考链接:opendir failed, Permission denied
opendir failed, Permission denied
此时,可先run-as your-package命令,如
run-as com.carlos.test
remote open failed: Permission denied
可用adb bugreport命令在当前路径下生成压缩包分析,参考链接:调试系列2:bugreport实战篇