Skip to content

Instantly share code, notes, and snippets.

@username13107
Created September 14, 2014 13:45
Show Gist options
  • Save username13107/55550755dd745e117e2e to your computer and use it in GitHub Desktop.
Save username13107/55550755dd745e117e2e to your computer and use it in GitHub Desktop.
build,sign,install apk
function bsign()
{
apktool b $1 $1.apk
if [ ! $? -eq 0 ];then
return
fi
jarsigner -digestalg SHA1 -sigalg MD5withRSA -keystore /Users/j0y/Desktop/cert.keystore -storepass 12345678 -keypass 12345678 -signedjar $1.signed.apk $1.apk cert.keystore
if [ ! $? -eq 0 ];then
return
fi
rm $1.apk
echo "====build and sign $1.signed.apk over====="
devices=`adb devices`
spdevices=`echo $devices | cut -c26- | sed 's: device *:|:g'`
recordn=`echo "$spdevices" | awk -v RS='|' 'END{print --NR}'`
#echo $spdevices
#echo $recordn
if [ $recordn -eq 0 ];then
echo "no device found"
return
fi
packagename=`aapt d badging ${1}.signed.apk | grep 'package: name' | cut -c16- | cut -f 1 -d "'"`
declare -a listdevices
echo ''
if [ $recordn -eq 1 ];then
echo "adb uninstall $packagename"
adb uninstall $packagename
adb install ${1}.signed.apk
return
fi
for((i=1;i<=$recordn;i++))
do
listdevices[$i]=`echo "$spdevices" | cut -f $i -d '|'`
echo "$i. ${listdevices[$i]}"
done
read -p "choose device to install or 0 to exit:" choose
if [ $choose -eq 0 -o $choose -gt $recordn ];then
return
fi
echo adb -s ${listdevices[$choose]} uninstall ${packagename}
adb -s ${listdevices[$choose]} uninstall ${packagename}
adb -s ${listdevices[$choose]} install $1.signed.apk
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment