Skip to content

Commit c9b4882

Browse files
committed
Merge branch 'sign-android'
2 parents 9b4f397 + 3e1f6c3 commit c9b4882

File tree

6 files changed

+85
-3
lines changed

6 files changed

+85
-3
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ qt-windows:
6666
$(MAKE) buildweb
6767
cd frontends/qt && $(MAKE) windows
6868
android:
69-
$(MAKE) buildweb
7069
cd frontends/android && ${MAKE} apk-debug
70+
# Create signed .apk and .aab.
71+
android-assemble-release:
72+
cd frontends/android && ${MAKE} assemble-release
7173
ios:
7274
cd frontends/ios && ${MAKE} build
7375
osx-sec-check:

docs/BUILD.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ To create the installer, run the NSIS UI, then: compile NSI scripts -> frontend/
114114
### Build
115115
Enter the Docker environment: `make dockerdev`
116116

117-
Within the Docker dev environment, build the Android App: `make android`
117+
Within the Docker dev environment, build the **debug version** of the Android App: `make android`
118118

119119
To update the app icon, execute `frontends/android/mkicon.sh`.
120120
The script isn't run during `make android` build.
@@ -129,6 +129,17 @@ After connecting the device via USB, it is possible to verify the connection wit
129129

130130
Inside `frontends/android` folder: `make deploy-debug`
131131

132+
### Release build
133+
134+
To assemble the signed release .apk and .aab files, run `make android-assemble-release`.
135+
136+
The keystore file `frontends/android/BitBoxApp/app/bitboxapp.jks` must be present.
137+
138+
Build artifacts:
139+
* `frontends/android/BitBoxApp/app/build/outputs/apk/release/app-release.apk`
140+
* `frontends/android/BitBoxApp/app/build/outputs/bundle/release/app-release.aab`
141+
142+
132143
### Deploy troubleshooting
133144
If the apk install goes wrong, here are some Android configuration that could help:
134145
* Enable developer options

frontends/android/BitBoxApp/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@
1717
/app/src/main/assets/web
1818
# Autogenerated mobileserver output
1919
/mobileserver/mobileserver.aar
20+
# Keystore is mounted inside docker only, but just to be sure we ignore it so
21+
# it is not accidentally committed.
22+
/app/bitboxapp.jks

frontends/android/BitBoxApp/app/build.gradle

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,23 @@ android {
1919
}
2020
}
2121
}
22+
signingConfigs {
23+
release {
24+
def env = System.getenv()
25+
if (env.containsKey('KEYSTORE_STORE_FILE')) {
26+
keyAlias env['KEYSTORE_KEY_ALIAS']
27+
keyPassword env['KEYSTORE_KEY_PASSWORD']
28+
storeFile file(env['KEYSTORE_STORE_FILE'])
29+
storePassword env['KEYSTORE_STORE_PASSWORD']
30+
}
31+
}
32+
}
2233
buildTypes {
2334
release {
2435
minifyEnabled false
2536
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
2637
resValue "string", "app_name", "BitBoxApp"
38+
signingConfig signingConfigs.release
2739
}
2840
debug {
2941
applicationIdSuffix ".debug"

frontends/android/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ include ../../android-env.mk.inc
22

33
apk-debug:
44
${MAKE} prepare-android
5-
cd BitBoxApp && ./gradlew assemble
5+
cd BitBoxApp && ./gradlew assembleDebug
6+
# Creates signed release .apk and .aab.
7+
assemble-release:
8+
./assemble_release.sh
69
deploy-debug:
710
adb install -r ./BitBoxApp/app/build/outputs/apk/debug/app-debug.apk
811
clean:
912
cd BitBoxApp && ./gradlew clean
1013
prepare-android:
14+
cd ../../ && ${MAKE} buildweb
1115
rm -rf BitBoxApp/app/src/main/assets/web
1216
mkdir -p BitBoxApp/app/src/main/assets/web
1317
cp -aR ../web/build/* BitBoxApp/app/src/main/assets/web/
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# make sure it's not exported
6+
unset -v key_password
7+
unset -v store_password
8+
9+
# make sure variables are not automatically exported
10+
set +o allexport
11+
12+
keystore=BitBoxApp/app/bitboxapp.jks
13+
key_alias=bitboxapp
14+
expected_fingerprint="Certificate fingerprint (SHA-256): 67:E9:05:08:F7:49:BE:9D:CF:B1:83:33:92:BA:99:EE:BF:89:37:B1:BA:DD:F3:05:63:1C:E2:D9:FB:A5:0B:D7"
15+
16+
if [[ ! -f "$keystore" ]]; then
17+
echo "Keystore file not found: $keystore"
18+
exit 1
19+
fi
20+
21+
echo "Enter keystore password:"
22+
IFS= read -rs store_password < /dev/tty
23+
24+
# check store password
25+
if ! keytool -list -keystore "$keystore" -storepass "$store_password" -alias "$key_alias" > /dev/null 2>&1; then
26+
echo "Invalid keystore password"
27+
exit 1
28+
fi
29+
30+
# check expected key exists
31+
if ! keytool -list -keystore "$keystore" -storepass "$store_password" 2>/dev/null | grep -q "$expected_fingerprint"; then
32+
echo "Keystore does not contain expected key"
33+
exit 1
34+
fi
35+
36+
echo "Enter password for key '$key_alias':"
37+
IFS= read -rs key_password < /dev/tty
38+
if ! keytool -certreq -keystore "$keystore" -storepass "$store_password" \
39+
-alias "$key_alias" -keypass "$key_password" > /dev/null 2>&1; then
40+
echo "Invalid key password"
41+
exit 1
42+
fi
43+
44+
export KEYSTORE_STORE_FILE=bitboxapp.jks
45+
export KEYSTORE_KEY_ALIAS="$key_alias"
46+
export KEYSTORE_KEY_PASSWORD="$key_password"
47+
export KEYSTORE_STORE_PASSWORD="$store_password"
48+
49+
make prepare-android
50+
(cd BitBoxApp && ./gradlew assembleRelease bundleRelease)

0 commit comments

Comments
 (0)