Skip to content

Commit 6470446

Browse files
committed
sign apk script for testing.
1 parent dbcb951 commit 6470446

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

tools/sign_apk.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
# === INPUT ===
6+
APK_UNSIGNED_PATH="$1"
7+
8+
if [ ! -f "$APK_UNSIGNED_PATH" ]; then
9+
echo "❌ APK not found at: $APK_UNSIGNED_PATH"
10+
exit 1
11+
fi
12+
13+
# === CONFIGURATION ===
14+
BUILD_TOOLS_VERSION=35.0.0
15+
KEYSTORE_PATH=temp-keystore.jks
16+
KEY_ALIAS=tempkey
17+
KEYSTORE_PASSWORD=temp123
18+
KEY_PASSWORD=temp123
19+
20+
# === SDK Tools ===
21+
ZIPALIGN="$ANDROID_SDK_ROOT/build-tools/$BUILD_TOOLS_VERSION/zipalign"
22+
APKSIGNER="$ANDROID_SDK_ROOT/build-tools/$BUILD_TOOLS_VERSION/apksigner"
23+
24+
# === TEMP FILES ===
25+
APK_ALIGNED_PATH="${APK_UNSIGNED_PATH%.apk}-aligned.apk"
26+
APK_SIGNED_PATH="${APK_UNSIGNED_PATH%.apk}-signed.apk"
27+
28+
echo "🧹 Cleaning up temporary files..."
29+
rm -f "$KEYSTORE_PATH" "$APK_ALIGNED_PATH"
30+
31+
# === GENERATE TEMP KEYSTORE ===
32+
echo "🔐 Creating temporary keystore..."
33+
keytool -genkey -v \
34+
-keystore "$KEYSTORE_PATH" \
35+
-alias "$KEY_ALIAS" \
36+
-keyalg RSA \
37+
-keysize 2048 \
38+
-validity 10000 \
39+
-storepass "$KEYSTORE_PASSWORD" \
40+
-keypass "$KEY_PASSWORD" \
41+
-dname "CN=Temp, OU=Dev, O=Example, L=City, S=State, C=US" \
42+
-noprompt
43+
44+
# === ZIPALIGN ===
45+
echo "📦 Aligning APK..."
46+
"$ZIPALIGN" -v -p 4 "$APK_UNSIGNED_PATH" "$APK_ALIGNED_PATH"
47+
48+
# === SIGN ===
49+
echo "✍️ Signing APK (v2 only)..."
50+
"$APKSIGNER" sign \
51+
--ks "$KEYSTORE_PATH" \
52+
--ks-key-alias "$KEY_ALIAS" \
53+
--ks-pass "pass:$KEYSTORE_PASSWORD" \
54+
--key-pass "pass:$KEY_PASSWORD" \
55+
--v1-signing-enabled false \
56+
--v2-signing-enabled true \
57+
--v3-signing-enabled false \
58+
--v4-signing-enabled false \
59+
--out "$APK_SIGNED_PATH" \
60+
"$APK_ALIGNED_PATH"
61+
62+
echo "✅ Verifying signed APK..."
63+
"$APKSIGNER" verify "$APK_SIGNED_PATH"
64+
65+
echo "📁 Replacing original APK with signed version..."
66+
mv -f "$APK_SIGNED_PATH" "$APK_UNSIGNED_PATH"
67+
echo "🎉 APK successfully signed with v2 and saved at: $APK_UNSIGNED_PATH"

0 commit comments

Comments
 (0)