Skip to content

Instantly share code, notes, and snippets.

@ph1ee
Created June 16, 2015 02:35
Show Gist options
  • Save ph1ee/5d2b8e3b5d3223607602 to your computer and use it in GitHub Desktop.
Save ph1ee/5d2b8e3b5d3223607602 to your computer and use it in GitHub Desktop.
APK Generator
#!/bin/bash
USERNAME=username
PASSWORD=password
REPO="svn://192.168.0.30/svn/trunk/android"
APK="pkg1 pkg2 pkg3 pkg4"
OUTDIR=$HOME/build.apk
BUILDLOG=buildlog
BUILTLST=builtlst
AUTH="--no-auth-cache --non-interactive --username $USERNAME --password $PASSWORD"
RANGE={$(date --date="yesterday" --iso-8601=minutes)}:{$(date --date="today" --iso-8601=minutes)}
############################################################
mkdir -p "$OUTDIR"
declare -A builtlst
for n in $(cat "$OUTDIR/$BUILTLST" 2>/dev/null); do
builtlst[$n]=1
done
############################################################
for apk in $APK
do
tmpfile=$(mktemp)
num=$(svn log $AUTH --stop-on-copy --xml -r $RANGE "$REPO/$apk" | tee $tmpfile | xmllint -xpath "count(/log/logentry)" -)
for ((i=0; i < $num; i++))
do
rev=$(xmllint -xpath "number(/log/logentry[$((i+1))]/@revision)" $tmpfile)
name=$(basename "$REPO/$apk")-r$rev
wc="$OUTDIR/$name"
# checkout & build
if [[ ! -d "$wc" && ! ${builtlst[$name]} ]]; then
svn checkout $AUTH --revision "$rev" --depth empty "$REPO" "$wc"
svn update $AUTH --revision "$rev" --depth infinity "$wc/share" "$wc/$apk" "$wc/keystore"
# generate build.xml
find "$wc" -type f -name AndroidManifest.xml |
while read path
do
android update project --target android-19 --path "$(dirname $path)"
done
# build
build_date=$(date +%Y%m%d%H%M%S)
(cd "$wc/$apk" && { ant debug && ant release; } 2>&1 | tee "$BUILDLOG") && chmod -R -w "$wc"
echo "$name" >> "$OUTDIR/$BUILTLST"
fi
done
rm -f $tmpfile
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment