Last active
January 18, 2021 08:53
-
-
Save rosuH/b7cccadc6dd7a692e9c17e31c4e72843 to your computer and use it in GitHub Desktop.
APK signer scripts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# 对路径下所有安装包进行签名 | |
# sign for all apk in specified path | |
function echoHelp() { | |
echo "Usage: $0 <unsignedFile PATH> <storeFile> <storePassword> <keyAlias> <keyPassword>" | |
} | |
if [[ ! -n $1 ]]; then | |
echoHelp | |
exit 0 | |
fi | |
# 待签名的 apk 文件夹 | |
# unsigned apk path | |
apk_path=$1 | |
# jsk key 路径, jsk key path | |
storeFile=$2 | |
# 存储密码, storePassword | |
storePass=$3 | |
# key 别名, key alias | |
keyAlias=$4 | |
# key 密码, key password | |
keyPass=$5 | |
count=$(ls | grep .apk | wc -l) | |
echo "apk count:$count" | |
cur_path="$apk_path" | |
apk_files="$cur_path"/*.apk | |
for apk in $apk_files | |
do | |
echo "current(当前):$apk" | |
echo "Begin (开始签名)🔑" | |
./sign_apk.sh "$apk" "$storeFile" "$storePass" "$keyAlias" "$keyPass" | |
echo "Done (签名完成)" | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# 对单个安装包进行签名 | |
# sign for single apk file | |
function echo_help() { | |
echo "Usage: <unsignedFile> <storeFile> <storePassword> <keyAlias> <keyPassword>" | |
} | |
function sign() { | |
if [[ ! -n $1 ]]; then | |
echo_help | |
exit 0 | |
fi | |
file=$1 | |
storeFile=$2 | |
storePass=$3 | |
keyAlias=$4 | |
keyPass=$5 | |
android_cmd="${ANDROID_HOME}/build-tools/29.0.3" | |
echo "zipalign apk, 对齐 apk" | |
zipaligncmd="$android_cmd"/zipalign | |
unaligned="${file})_unaligned" | |
mv "$file" "$unaligned" | |
$zipaligncmd -p 4 "$unaligned" "$file" | |
rm "$unaligned" | |
apksignercmd="$android_cmd"/apksigner | |
echo "apksigner 签名中" | |
$apksignercmd sign --ks "$storeFile" --ks-pass pass:"$storePass" \ | |
--ks-key-alias "$keyAlias" -key-pass pass:"$keyPass" \ | |
--v1-signing-enabled true \ | |
--v2-signing-enabled true \ | |
"$file" | |
} | |
sign "$1" "$2" "$3" "$4" "$5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# You need to set the Java env path. | |
if [ -z "$1" ]; then | |
echo "Specify you apk,pls" | |
exit 0 | |
fi | |
apksigner verify -v --print-certs "$1" | grep -E '(Signer|Verifie)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment