Android一些常用命令

2017-02-24  本文已影响0人  retton

开发调试常用命令列表

记录并收集一些开发调试过程中有效的命令,主要是Android相关。

1 通用命令

1.1 iptables

iptables -I OUTPUT 1 -m hashlimit --hashlimit-name testup --hashlimit-above 5/s -j DROP
iptables -I INPUT 1 -m hashlimit --hashlimit-name testdown --hashlimit-above 5/s -j DROP
iptables -I INPUT 1  -m statistic --mode random  --probability 0.8 -j DROP
iptables --list
iptables -F

1.2 find

busybox find [PATH] -size +10000k
find /root -size -5557c -size +5555c -exec ls -ld {} \;
find . -name "*.java" | xargs grep -HRn 'AudioFormat.ENCODING_PCM_16BIT'
busybox find /sdcard/test/ -maxdepth 4

1.3 mount

sudo mount -t vboxsf share /mnt
mount.cifs -o username=username /////////////////path to ci package

1.4 计算器

echo | awk '{print (126+39+35+18+12+12+11+11+0.1)/4}'

1.5 sed

分析日志

// 查找识别结果
sed -n 's/.*,\("text":"[^"]*"\),.*/\1/p' log.txt
sed -n 's/.*SrSolution: ISS_SR_MSG_RESULT.*,\("text":"[^"]*"\),.*/\1/p' log.txt

2.adb命令

2.1 包管理相关

dumpsys package com.test.test
// 打开Android原生设置页面
am start -n com.android.settings/.Settings
am start "intent:#Intent;action=android.media.action.MEDIA_PLAY_FROM_SEARCH;\
S.android.intent.extra.focus=vnd.android.cursor.item%2Fartist;\
S.android.intent.extra.artist=Adele;end"
am start "intent:#Intent;action=android.intent.action.VIEW;\
category=android.intent.category.BROWSABLE;launchFlags=0x10200000;\
component=com.retton.h5/.WebActivity;\
S.title=%E6%97%A5%E6%9C%9F%2F%E6%97%B6%E9%97%B4;\
S.url=http%3A%2F%2Fwww.pingwest.com;end"
am startservice -a com.test.VoiceKey -e StartFrom HomeVoiceButton
adb shell "am startservice -a com.test.dictionary -e param test -e data '"'[{"group":"","location":{"city":"合肥","country":"中国","province":"安徽"},"name":"张小三","phoneNumber":"13019001001","teleOper":"联通","type":"工作"}]'"'"
adb shell "am startservice ... '"'JSON_TEXT'"'"

2.2 logcat

adb logcat | sed -n 's/.*intent.*,"text":"\([^"]*\)",.*/\1/p'
logcat | busybox grep `ps | busybox grep "com.package.name$" | busybox awk -F " " '{print $2}'`
logcat | busybox grep `ps | busybox grep "com.package.name$" | busybox awk 'NR%2==1{T=$2;next}{print T"|"$2}'
logcat | grep -E `ps |grep account| busybox awk 'NR%2==1{T=$2;next}{printf T"|"$2}'`
adb logcat -vtime -d > ~/Desktop/dump.log

2.3 网络抓包

tcpdump -i usb0 -s0 -w /data/local/tmp/`date "+%Y%m%d%H%M%S"`.pcap
tcpdump -i usb0 -s0 -vv tcp port 80 and host hostname

2.4 monkey命令

monkey -p com.package.name --pct-syskeys 0 100000

2.5 系统命令

svc wifi [enable|disable]
svc data [enable|disable]
input keyevent [--longpress] <key code number or name>
input keyevent HOME
input keyevent BACK

2.6 系统分析

echo 'H' | busybox top -d 1 | busybox tee /sdcard/top_`date "+%Y%m%d%H%M%S"`.log
debuggerd -b [pid]
kill -3 [pid]
uiautomator dump /sdcard/dump.xml
cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq
cat /proc/PID/oom_adj

3.签名工具

3.1 列出密钥库中的条目

keytool -list -v -keystore debug.keystore

3.2 打印APK解压出来的证书内容

通过此方法能查看APK的签名信息,包括SHA1等。

keytool -printcert -file META-INF/CERT.RSA

3.3 使用keystore给unsigned apk签名

jarsigner -verbose -keystore [keystorePath] -signedjar [apkOut] [apkIn] [alias]

3.4 验证APK的签名状态

jarsigner -verbose -verify -certs [apk]

3.5 查看APK信息

aapt dump badging {PATH}.apk

3.6 系统签名导入keystore

将一般ROM的系统签名(pk8私钥和pem公钥)导入到keystore中方便在ide或ci中自动化构建,步骤如下:

openssl pkcs8 -inform DER -nocrypt -in platform.pk8 -out key.pem
openssl pkcs12 -export -in platform.x509.pem -inkey key.pem -out platform.p12 -password pass:test -name test
keytool -importkeystore -deststorepass test -destkeystore test.jks -srckeystore platform.p12 -srcstoretype PKCS12 -srcstorepass test
keytool -list -v -keystore test.jks

4.git

4.1 gitbash

Windows系统通过gitbash默认push文件到android系统时会出现文件系统解析错误,导致找不到目标路径,需在目标系统路径前增加“/”:

adb push myfile //{path}/myfile

4.2 git

#删除对文件的跟踪,会修改commit id,只在本地使用
git filter-branch --tree-filter 'rm -f testme.txt' HEAD

忽略merge日志
git log --no-merges

查看从v2.6.12开始include/scsi和drivers/scsi目录中的改动的日志
git log v2.6.12.. include/scsi drivers/scsi

导出两周前开始的修改记录到文件gitk,“--”是为了避免和名为gitk的分支冲突
git log --since="2 weeks ago" -- gitk

查看test分支有但release分支没有的提交记录,并显示提交记录修改的路径信息
git log --name-status release..test

查看指定文件的修改记录,包含该文件被重命名等操作前的修改记录
git log --follow builtin/rev-list.c

本地有而远端没有的提交记录
git log --branches --not --remotes=origin

本地master分支有而远端master分支没有的提交记录
git log master --not --remotes=*/master

git log -p -m --first-parent

Shows the history including change diffs, but only from the “main branch” perspective, skipping commits that come from merged branches, and showing full diffs of changes introduced by the merges. This makes sense only when following a strict policy of merging all topic branches when staying on a single integration branch.

git log -L '/int main/',/^}/:main.c

Shows how the function main() in the file main.c evolved over time.

上一篇下一篇

猜你喜欢

热点阅读