Skip to content

Instantly share code, notes, and snippets.

@JakeSteam
Last active December 15, 2020 10:27
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JakeSteam/eacc45ddd0db942d6902150f09dfa39f to your computer and use it in GitHub Desktop.
Save JakeSteam/eacc45ddd0db942d6902150f09dfa39f to your computer and use it in GitHub Desktop.
Creating app bundles and APKs on Travis CI (for https://wp.me/paoKlI-Gk)
# Overall config
dist: xenial
language: android
# Android version config
android:
components:
- build-tools-28.0.3
- android-28
# Scripts
before_install: # Make sure build scripts can be executed
- chmod 755 build-scripts/*.sh
script: # Runs build script
- build-scripts/travis_build.sh $TRAVIS_BRANCH $KEYSTORE_PASSWORD $KEYSTORE_KEY_PASSWORD
#!/usr/bin/env bash
TERM=dumb # Don't use any fancy escape sequences / colours, we're on a basic terminal!
# Travis variables
TRAVIS_BRANCH=$1
# Debug build variables
DEBUG_BUNDLE_PATH=${TRAVIS_BUILD_DIR}/app/build/outputs/bundle/prodDebug/
DEBUG_KEYSTORE_PATH=${TRAVIS_BUILD_DIR}/app/build-extras/debug.keystore
DEBUG_KEYSTORE_PASSWORD=android
DEBUG_KEYSTORE_ALIAS=AndroidDebugKey
DEBUG_KEYSTORE_KEY_PASSWORD=android
# Release build variables
RELEASE_BUNDLE_PATH=${TRAVIS_BUILD_DIR}/app/build/outputs/bundle/prodRelease/
RELEASE_KEYSTORE_PATH=${TRAVIS_BUILD_DIR}/app/build-extras/upload-keystore.jks
RELEASE_KEYSTORE_PASSWORD=$2
RELEASE_KEYSTORE_ALIAS=mykey
RELEASE_KEYSTORE_KEY_PASSWORD=$3
function compileAndTestDebugBundle {
echo "Compiling and testing a debug bundle!"
./gradlew app:bundleDebug
}
function convertBundleToApk {
# Check all necessary arguments have been passed
if [[ "$#" -eq 5 ]]; then
echo "Converting bundle to APK!"
else
echo "Make sure you pass in a bundle path, and all 4 keystore values!"
exit 1
fi
# Download bundletool
curl -O -L "https://github.com/google/bundletool/releases/download/0.11.0/bundletool-all-0.11.0.jar"
# Use bundletool to create universal .apks zip
java -jar bundletool-all-0.11.0.jar build-apks \
--mode=universal \
--bundle=${1}app.aab \
--output=${1}app.apks \
--ks=${2} \
--ks-pass=pass:${3} \
--ks-key-alias=${4} \
--key-pass=pass:${5};
# Unzip .apks zip into /unzipped
unzip ${1}app.apks -d ${1}unzipped;
}
compileAndTestDebugBundle;
convertBundleToApk ${DEBUG_BUNDLE_PATH} ${DEBUG_KEYSTORE_PATH} ${DEBUG_KEYSTORE_PASSWORD} ${DEBUG_KEYSTORE_ALIAS} ${DEBUG_KEYSTORE_KEY_PASSWORD}
uploadToDeployGate; # Not covered in this tutorial
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment