闲来无事,写了一个安卓app安装的bash脚本。在Mac OS下测试通过。
用法很简单:
./appManager.sh 要安装的app.apk
如果跟电脑连接的安卓设备上已经安装了此apk,它会提示你要不要卸载。如果没有安装的话,它会安装,安装完成后会打开。
运行脚本前,需要下载Android SDK,并在~/.bash_profile里加一行,指定aapt的路径。
alias aapt="/Users/你的用户名/Library/Android/sdk/build-tools/28.0.3/aapt"
上面的路径要根据你的情况修改。
脚本内容如下:
#!/bin/bash
if [ $# -eq 0 ] || [ -z "$1" ]
then
echo "No arguments supplied"
echo "Usage: ./appManager.sh yourApk.apk"
exit
fi
if (("$#" > 1))
then
echo "More than one file is provided."
echo "Please only give one file as argument"
echo "Usage: ./appManager.sh yourApk.apk"
exit
fi
if [[ ! -f $1 ]]; then
echo "Your Apk file does not exist."
exit
fi
apk=$1
packageName=`aapt dump badging "$apk" | grep package:\ name | awk '{print $2}' | cut -d "'" -f 2`
echo -ne "Package Name of "$apk" : "
echo $packageName
packageInDevice=`adb shell pm list packages|grep $packageName|cut -d ":" -f 2`
#echo $packageInDevice
if [ "$packageName" = "$packageInDevice" ] ; then
echo "This app is already installed in the device."
while true; do
read -p "Uninstall the app now? " yn
case $yn in
[Yy]* ) adb uninstall $packageName; exit;;
[Nn]* ) break;;
* ) echo "Please type in y or n";;
esac
done
else
while true; do
read -p "Install the app now? " yn
case $yn in
[Yy]* ) adb install $apk; break;;
[Nn]* ) exit;;
* ) echo "Please type in y or n";;
esac
done
fi
read -p "Start the app now? " yn
case $yn in
[Yy]* ) adb shell monkey -p $packageName -c android.intent.category.LAUNCHER 1 > /dev/null 2>&1; exit;;
[Nn]* ) exit;;
* ) echo "Please type in y or n";;
esac
网友评论