Skip to content

Commit 97cd1fd

Browse files
author
Eric Wheeler
committed
added repack-n-sign helper
1 parent cf868fc commit 97cd1fd

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

repack-n-sign.sh

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/sh
2+
3+
BUILD_TOOLS=~/Android/Sdk/build-tools/32.0.0/
4+
5+
if [ -z "$1" ]; then
6+
echo "usage: $0 your-app.apk"
7+
exit 1
8+
fi
9+
10+
DIR=`mktemp -d`
11+
DN=`dirname "$1"`
12+
BN=`basename "$1"`
13+
OUT="$DN/repacked-$BN"
14+
OUT_ALIGNED="$DN/aligned-$BN"
15+
OUT_SIGNED="$DN/signed-$BN"
16+
17+
# Debug mode
18+
set -x
19+
20+
# Repack without the META-INF in case it was already signed
21+
# and flag resources.arsc as no-compress:
22+
unzip -q "$1" -d "$DIR"
23+
pushd .
24+
cd $DIR
25+
26+
rm -rf "$DIR/META-INF"
27+
zip -n "resources.arsc" -r ../repacked.$$.apk *
28+
29+
popd
30+
31+
mv "$DIR/../repacked.$$.apk" "$OUT"
32+
33+
# Align
34+
rm -f "$OUT_ALIGNED"
35+
"$BUILD_TOOLS"/zipalign -p -v 4 "$OUT" "$OUT_ALIGNED"
36+
37+
# Verify
38+
"$BUILD_TOOLS"/zipalign -vc 4 "$OUT_ALIGNED"
39+
40+
# Sign
41+
"$BUILD_TOOLS"/apksigner sign -verbose -ks ~/my-release-key.keystore --out "$OUT_SIGNED" "$OUT_ALIGNED"
42+
43+
# Cleanup
44+
rm -rf "$DIR"
45+
46+
echo == Done: $OUT_ALIGNED

0 commit comments

Comments
 (0)