Skip to content
This repository was archived by the owner on Dec 18, 2022. It is now read-only.

Commit 5d06765

Browse files
committed
add split apks to build output & update signing script to reflect the change
1 parent 5a817bb commit 5d06765

2 files changed

Lines changed: 59 additions & 36 deletions

File tree

sampleapp/build.gradle

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,31 @@ android {
4545
kotlinOptions {
4646
jvmTarget = JavaVersion.VERSION_1_8
4747
}
48+
49+
// https://github.com/guardianproject/tor-android/blob/master/sampletorapp/build.gradle
50+
splits {
51+
52+
// Configures multiple APKs based on ABI. This helps keep the size
53+
// down, since PT binaries can be large.
54+
abi {
55+
56+
// Enables building multiple APKs per ABI.
57+
enable true
58+
59+
// By default all ABIs are included, so use reset() and include to specify
60+
// that we only want APKs for x86 and x86_64, armeabi-v7a, and arm64-v8a.
61+
62+
// Resets the list of ABIs that Gradle should create APKs for to none.
63+
reset()
64+
65+
// Specifies a list of ABIs that Gradle should create APKs for.
66+
include "x86", "armeabi-v7a", "arm64-v8a", "x86_64"
67+
68+
// Specify whether or not you wish to also generate a universal APK that
69+
// includes _all_ ABIs.
70+
universalApk true
71+
}
72+
}
4873
}
4974

5075
//repositories {

scripts/sign_sampleapp_release_build.sh

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
2626

2727
# Check for pkcs11 config file
2828
PKCS11_CFG="$DIR/.pkcs11_java.cfg"
29-
if [ ! -f $PKCS11_CFG ]; then
29+
if [ ! -f "$PKCS11_CFG" ]; then
3030
echo "File not found:"
3131
echo "$PKCS11_CFG"
3232
exit 1
@@ -35,7 +35,7 @@ fi
3535
# Get Build Tools Version from project's /gradle/dependencies.gradle file
3636
FILE="$DIR/../gradle/dependencies.gradle"
3737

38-
if [ ! -f $FILE ]; then
38+
if [ ! -f "$FILE" ]; then
3939
echo "File not found:"
4040
echo "$FILE"
4141
exit 1
@@ -51,44 +51,42 @@ MAX_SDK_VERSION=$(cat $FILE | grep 'compileSdk' | grep -o '[[:digit:]]*')
5151

5252
# Locate unsigned release
5353
UNSIGNED_APK_DIR="$DIR/../sampleapp/build/outputs/apk/release"
54-
UNSIGNED_APK="$UNSIGNED_APK_DIR/sampleapp-release-unsigned.apk"
55-
56-
if [ ! -f $UNSIGNED_APK ]; then
57-
echo "File not found:"
58-
echo "$UNSIGNED_APK"
59-
echo ""
60-
echo "An unsigned release version is needed. Please build one with Android Studio."
61-
exit 1
62-
fi
54+
UNSIGNED_APK_DIR_FILE_LIST=$(ls "$UNSIGNED_APK_DIR"/)
6355

6456
# Get Yubikey PIN
6557
read -p "Please enter your Yubikey PIV pin: " YUBI_PIN
6658

67-
# Zipalign
68-
echo "zipaligning the apk"
69-
echo ""
70-
$ANDROID_SDK/build-tools/$BUILD_TOOLS_VERSION/zipalign 4 \
71-
$UNSIGNED_APK $UNSIGNED_APK.tmp && mv -vf $UNSIGNED_APK.tmp $UNSIGNED_APK
72-
73-
echo ""
74-
echo "signing"
75-
echo ""
76-
77-
# Signing
78-
$ANDROID_SDK/build-tools/$BUILD_TOOLS_VERSION/apksigner sign \
79-
--ks NONE \
80-
--ks-pass "pass:$YUBI_PIN" \
81-
--min-sdk-version $MIN_SDK_VERSION \
82-
--max-sdk-version $MAX_SDK_VERSION \
83-
--provider-class sun.security.pkcs11.SunPKCS11 \
84-
--provider-arg $PKCS11_CFG \
85-
--ks-type PKCS11 \
86-
--out $UNSIGNED_APK_DIR/sampleapp-release-signed.apk \
87-
$UNSIGNED_APK
88-
89-
# Output Verfication
90-
$ANDROID_SDK/build-tools/$BUILD_TOOLS_VERSION/apksigner verify --verbose \
91-
$UNSIGNED_APK_DIR/sampleapp-release-signed.apk
59+
for FILE in $UNSIGNED_APK_DIR_FILE_LIST; do
60+
if echo "$FILE" | grep -q ".*release-unsigned.apk"; then
61+
# Zipalign
62+
echo "zipaligning the apk"
63+
echo ""
64+
"$ANDROID_SDK"/build-tools/"$BUILD_TOOLS_VERSION"/zipalign 4 \
65+
"$UNSIGNED_APK_DIR"/"$FILE" "$FILE".tmp && mv -vf "$FILE".tmp "$FILE"
66+
67+
echo ""
68+
echo "Signing"
69+
echo ""
70+
71+
SIGNED_APK_NAME=$(echo "$FILE" | sed 's+unsigned+signed+g')
72+
73+
# Signing
74+
"$ANDROID_SDK"/build-tools/"$BUILD_TOOLS_VERSION"/apksigner sign \
75+
--ks NONE \
76+
--ks-pass "pass:$YUBI_PIN" \
77+
--min-sdk-version "$MIN_SDK_VERSION" \
78+
--max-sdk-version "$MAX_SDK_VERSION" \
79+
--provider-class sun.security.pkcs11.SunPKCS11 \
80+
--provider-arg "$PKCS11_CFG" \
81+
--ks-type PKCS11 \
82+
--out "$UNSIGNED_APK_DIR"/"$SIGNED_APK_NAME" \
83+
"$UNSIGNED_APK_DIR"/"$FILE"
84+
85+
# Output Verfication
86+
"$ANDROID_SDK"/build-tools/"$BUILD_TOOLS_VERSION"/apksigner verify --verbose \
87+
"$UNSIGNED_APK_DIR"/"$SIGNED_APK_NAME"
88+
fi
89+
done
9290

9391
unset YUBI_PIN
9492
exit 0

0 commit comments

Comments
 (0)