Skip to content

Instantly share code, notes, and snippets.

@packmad
Created January 25, 2019 13:52
Show Gist options
  • Save packmad/e7961a64e1495bef31962bdab99c96eb to your computer and use it in GitHub Desktop.
Save packmad/e7961a64e1495bef31962bdab99c96eb to your computer and use it in GitHub Desktop.
Rebuild Android apk
#!/bin/bash
if [ -d "$1" ]; then
apktool build $1
dist="$1/dist/"
cd $dist
outapk="out.apk"
if [ -f $outapk ]; then
rm $outapk
echo "$outapk previous version removed."
fi
align=$(zipalign -f -v 4 *.apk $outapk | tail -1)
if [[ $align = "Verification succesful" ]]; then
echo "$outapk aligned."
sign=$(jarsigner -sigalg SHA1withRSA -digestalg SHA1 -keystore ~/.android/debug.keystore $outapk androiddebugkey -storepass android)
if [[ $sign = "jar signed."* ]]; then
echo "$outapk signed. Realpath:"
realpath $outapk
adbdevices=$(adb devices | wc -l)
if [[ $adbdevices = "3" ]]; then
adbinstall=$(adb install -r $outapk)
if [[ $adbinstall = "Success" ]]; then
echo "$outapk installed"
fi
fi
fi
fi
else
echo "Usage: rebuildapk.sh apktoolOutputDirectory/"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment