← Back to list

How to automate the ionic build [Updated 2024]

Hello everyone, This is my first blog on medium. Today I am going to show you “How can automate the build process in Ionic“.

Deepak Ranjan · 2021-09-07 15:25 · 38 claps · 2.0 min read paywalled
#javascript #angular #ionic-framework #android #ionic3
Open on Medium ↗
Wiki topics: 🌐 · Web Development

How to automate the ionic build [Updated 2024]

Hello everyone, This is my first blog on medium. Today I am going to show you “How can automate the build process in Ionic“.

I was working on a project and for build apk file, every time I ran this command manually:-

Generating a key (if you have key then skip this step)

keytool -genkey -v -keystore my-release-key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias my-alias

#Signing

apksigner sign — ks key.jks — v1-signing-enabled true — v2-signing-enabled true app-release-unsigned.apk

#Compress

zipalign -v 4 app-release-unsigned.apk HelloWorld.apk

#Verify

apksigner verify HelloWorld.apk

I think this is a very tedious job. So, I decided to write an automated process with the help of Shell Scripting. Please follow these steps:-

Step 1. Make a file with an extension of sh in the root directory. Example- build.sh

Step 2. Copy the below code.

#!/bin/bash
CONFIG_FILE="config.xml"
APP_NAME=$(awk -F '[<>]' '/<name>/ {print $3}' "$CONFIG_FILE" | head -n 1)
echo -e "App Name: $APP_NAME"
#Remove spaces and convert to lowercase
APP_NAME_NO_SPACES_LOWER=$(echo "${APP_NAME// /}" | tr '[:upper:]' '[:lower:]')
echo -e "APP_NAME_NO_SPACES: $APP_NAME_NO_SPACES_LOWER"
VERSION=$(awk -F 'version="' '/<widget/ {print $2}' "$CONFIG_FILE" | cut -d'"' -f1)
echo -e "App Version: $VERSION"
<<multi-line-comment
“To print colored text, enter the following command:”
#Colors — reset = 0, black = 30, red = 31, green = 32, yellow = 33, blue = 34, magenta = 35, cyan = 36, and white = 37
##echo -e “\e[1;31m This is red text \e[0m”
##Emoji: https://emojipedia.org/
multi-line-comment
### Variables ###
HOME_PATH=/home/deepak
ANDROID_SDK=$HOME_PATH/android_sdk/build-tools/32.0.0
KEYSTORE=$HOME_PATH/<project_dir>/keystore.jks
RELEASE_APK_PATH=$HOME_PATH/<project_dir>/platforms/android/app/build/outputs/apk/release
APK_FILE="${APP_NAME_NO_SPACES_LOWER}_${VERSION}.apk"
SECRET='XXXXXXX'
### End ###
echo -e "\e[1;31m 🔨🔨🔨 Building 🔨🔨🔨 \e[0m"
if [ "$ANDROID_HOME" ]; then
ionic cordova build android --prod --release
else
ionic cordova build ios --prod --release
fi
echo -e "\e[1;31m 🔨🔨🔨 Building Completed 🔨🔨🔨 \e[0m"
# Check if the APK file exists
if [ -f "$RELEASE_APK_PATH/$APK_FILE" ]; then
# Delete the APK file
rm "$RELEASE_APK_PATH/$APK_FILE"
echo "$APK_FILE has been deleted."
fi
echo -e "\e[1;34m 🗜️🗜️🗜️ Compress 🗜️🗜️🗜️ \e[0m"
"$ANDROID_SDK/zipalign" -v 4 "$RELEASE_APK_PATH/app-release-unsigned.apk"
"$RELEASE_APK_PATH/${APP_NAME_NO_SPACES_LOWER}_${VERSION}.apk"
echo -e "\e[1;34m 🗜️🗜️🗜️ Compress Completed 🗜️🗜️🗜️ \e[0m"
echo -e "\e[1;33m 🔑🔑🔑 Signing 🔑🔑🔑 \e[0m"
"$ANDROID_SDK/apksigner" sign --ks $KEYSTORE --v1-signing-enabled true --v2-signing-enabled true "$RELEASE_APK_PATH/${APP_NAME_NO_SPACES_LOWER}_${VERSION}.apk"
echo -e "\e[1;33m 🔑🔑🔑 Signing Completed 🔑🔑🔑  \e[0m"
echo -e "\e[1;34m 🔥🔥🔥 Verify 🔥🔥🔥 \e[0m"
"$ANDROID_SDK/apksigner" verify "$RELEASE_APK_PATH/${APP_NAME_NO_SPACES_LOWER}_${VERSION}.apk"
echo -e "\e[1;34m 🔥🔥🔥 Verify Completed 🔥🔥🔥 \e[0m"

Step 3. Make build.sh file as executable

chmod +x build.sh

Step 4. Run this script. Example- ./build.sh or include in your package.json file.


메타데이터
post_id
3d55eb6568ba
slug
how-to-automate-the-ionic-build-3d55eb6568ba
url
https://medium.com/@rranjan306/how-to-automate-the-ionic-build-3d55eb6568ba
canonical_url
https://medium.com/@rranjan306/how-to-automate-the-ionic-build-3d55eb6568ba
author_url
https://medium.com/@rranjan306
status
ok
fetched_at
2026-07-28 00:23:04