A release needs a new versionCode, a build signed with the upload key, a check of that signature and a test install. Older guides zipaligned and signed the APK by hand after the build; cordova-android's Gradle 19,597 build now signs as it builds, from build.json (Upload Keystore) and the passwords you pass:
#!/usr/bin/env bash
# release: compile BookNest for Google Play and for testing, check the signature, install
set -euo pipefail
cd "$(dirname "$0")"
code="${1:?usage: ./release <versionCode> [serial]}" # e.g. ./release 10001
target="${2:-emulator-5554}"
: "${BOOKNEST_STORE_PASS:?export BOOKNEST_STORE_PASS first}"
args=(--gradleArg=-PcdvVersionCode="$code"
--storePassword="$BOOKNEST_STORE_PASS" --password="$BOOKNEST_STORE_PASS")
out=platforms/android/app/build/outputs
# 1. compile and sign: an .aab for Google Play, then an .apk for devices
cordova build android --release -- "${args[@]}" > build.log 2>&1
cordova build android --release -- "${args[@]}" --packageType=apk >> build.log 2>&1
ls $out/bundle/release $out/apk/release
# 2. check the signature
"$ANDROID_HOME"/build-tools/36.0.0/apksigner verify --print-certs \
$out/apk/release/app-release.apk | grep -E "certificate (DN|SHA-256)"
# 3. install
adb -s "$target" install -r $out/apk/release/app-release.apkAfter --, -PcdvVersionCode=10001 overrides the version code from config.xml (Identity and Preferences) and --packageType=apk asks for an APK instead of the release default, a bundle. Logs go to build.log:
export BOOKNEST_STORE_PASS='...' # your keystore password, typed once per terminal session
./release 10001 emulator-5558platforms/android/app/build/outputs/apk/release:
app-release.apk
...
app-release.aab
Signer #1 certificate DN: CN=BookNest Team, O=Example Books, L=Kota Kinabalu, C=MY
Signer #1 certificate SHA-256 digest: aaf472d58e4e5da350edb3be06e6ad932a63de8c718ac06961403333a
7db72c9
Performing Streamed Install
adb: failed to install platforms/android/app/build/outputs/apk/release/app-release.apk:
Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE: Existing package com.example.booknest
signatures do not match newer version; ignoring!]Both builds and the signature check passed (the digest is Upload Keystore's fingerprint). The install failed, as it should: the emulator still held the debug build, signed with the debug key, and Android never lets a differently signed APK replace an installed app. adb -s emulator-5558 uninstall com.example.booknest (which also deletes the app's data) followed by a plain adb install of the same APK succeeded, and dumpsys package then reported versionCode=10001. On Windows, the same steps fit a release.bat in the style of Batch Files, with call before each cordova.