mac shell脚本自动安装指定apk到安装android手机

sh代码:

#! /bin/bash
apkPath=$1
packageName=com.demo.test
mainActivityName=$packageName.MainActivity

echo installing...

if (adb install -r $apkPath | grep 'Failure') then
    echo uninstalling...
    adb shell pm uninstall $packageName
    echo reinstalling...
    adb install -r $apkPath
    echo success!
else
    echo success!
fi
adb shell am start -n $packageName/$mainActivityName

将文件存为:

/Users/touch_ping/Documents/apkInstall.sh 

赋予允许权限shell:chmod +x /Users/touch_ping/Documents/apkInstall.sh 

运行示范:/Users/touch_ping/Documents/apkInstall.sh  /Users/touch_ping/Documents/apk/1.0.6.0518.apk


shell的一些知识:

shell赋值:path=$1 中间不能有空格

if的语法:

if (true) then 

...

else 

...

fi #end if

判断安装是否失败,可能是签名不一致导致的

adb install -r $apkPath | grep 'Failure'



你可能感兴趣的:(shell,mac)