android开发几个常用的开发脚本,其实非常简单,我们参考下面二个文档。但是,我打算直接简化,特别是对于只有一行命令的脚本,直接命令化,这样更方便使用。
该脚本打印了包含崩溃,异常,dalvikvm信息,严格模式和网页CONSOLE等信息。
#!/bin/sh
#Explanations:
# System.err to grep stacktrace information of catched exceptions
#AndroidRuntime to grep stacktrace information of uncaughted runtime exceptions
#MessageQueue to grep exceptions happended during MessageQueue
#CONSOLE to grep console message releated with javascript console.info
#dalvikvm informations about dalvik vm
#StrictMode information about StrictMode warnings
adb logcat |grep --color=always -E "System.err|AndroidRuntime|MessageQueue|CONSOLE|W/Bundle|dalvikvm|StrictMode"
其实就一行命令,我们直接简化如下来使用:
adb logcat |grep -E "System.err|AndroidRuntime|MessageQueue|CONSOLE|W/Bundle|dalvikvm|StrictMode"
参考http://blog.csdn.net/hfreeman2008/article/details/51737790
#!/bin/bash
PackageName=$1
#PackageName=com.example.appinfomanagertinno
pid="$(adb shell ps | grep $PackageName | awk '{print $2}')"
echo "PackageName-----"
echo "$PackageName"
echo "-----------------------------------------"
echo "-----------------------------------------"
echo "pid-----"
echo "$pid"
echo "-----------------------------------------"
echo "-----------------------------------------"
adb logcat | grep $pid
脚本使用方法
./log_package.sh 包名
比名,我们要打印包com.example.appinfomanagertinno
./log_package.sh com.example.appinfomanagertinno
使用这个,我们可以快速的打开应用详情界面,快速完成卸载,强制停止,清除缓存,数据等操作
#!/bin/sh
adb shell am start -a "android.settings.APPLICATION_DETAILS_SETTINGS" -d "package:$1"
使用如下:
./clearAppData.sh com.droidyue.akoi
gfindx.sh
grep -E $1 --exclude-dir={.git,lib,.gradle,.idea,build,captures} --exclude={*.png,*.jpg,*.jar} . -R --color=always -n
上面的脚本,排除了.git,lib,.gradle,.idea等文件夹下的文件,也排除了类似png,jpg,jar等文件的查找,大大加快了查找效率。
其实这个,我们可以用此命令来替换,非常方便使用:
grep -rnwi --exclude-dir={.git,lib,.gradle,.idea,captures,out,prebuilts} --exclude={*.png,*.jpg,*.jar,*.so} "ro.hwui.texture_cache_size" ./
adb shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp' --color=always
其实我们也可以用下面这个命令来实现:
adb shell dumpsys activity | grep mFocusedActivity
adb shell top -m 20
#!/bin/bash
echo "----------test start!!!---------"
for i in {1..1000};
do
echo $i
adb root
#adb shell procrank | grep -i camera
#adb shell procrank | grep -i "RAM:"
adb shell procrank
done
echo "----------test end!!!---------"
#!/bin/bash
while true; do
adb shell procrank | grep -i "launcher"
sleep 1
done
#!/bin/bash
RELEASE=`date +%Y%m%d%H%M%S`
#echo $RELEASE
adb shell screencap /sdcard/${RELEASE}.png
adb pull /sdcard/${RELEASE}.png ./
nautilus ./
adb root
adb remount
#adb pull contact
#adb pull /data/data/com.android.providers.contacts/databases ./contact/
#adb pull launcher
#adb pull /data/data/com.ape.launcher3/databases ./launcher/
adb pull /data/data/com.wiko.launcher/databases ./launcher/
nautilus ./
#!/bin/bash
# ##########################################################
# ALPS(Android4.1 based) build environment profile setting
# ##########################################################
# Overwrite JAVA_HOME environment variable setting if already exists
########################################################################
##############################java 1.8##################################
########################################################################
#export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_151
#export PATH=/usr/lib/jvm/jdk1.8.0_151/bin:$PATH
#export JRE_HOME=${JAVA_HOME}/jre
#export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
#export ANDROID_JAVA_HOME=/usr/lib/jvm/jdk1.8.0_151
########################################################################
##############################java 1.7##################################
########################################################################
#set java 1.7
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export ANDROID_JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
########################################################################
##############################java 1.6##################################
########################################################################
#set java 1.6
#export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64
#export PATH=/usr/lib/jvm/java-6-openjdk-amd64/bin:$PATH
#export JRE_HOME=${JAVA_HOME}/jre
#export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
#export ANDROID_JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64
(1)http://www.androidchina.net/4878.html
快速提高Android开发的脚本与技巧(终端篇)
(2)https://github.com/androidyue/DroidScripts
开发脚本