This is a bash script to delegate building Android APKs and sharing them with stakeholders to a machine because you have better things to do in life !!
- Take up any discarded system(Linux or Mac, come on, do you still use Windows ?) and connect it to your network with a static IP assigned to it. Get your SysAd on it if you feel lazy.
- Install your project along with git to any place on that system.
- [Optional] Create a new user on that system and give necessary permissions to execute files on your project. You can use any existing user also.
- Add the script anyplace in the system(I suggest you keep the script in the root directory to easily access when you ssh into the system)
- Change the
RELATIVEPATH
variable at the first line of the script according to where your Android project is wrt the script.
RELATIVEPATH="ixigo_android/ixigo-app-android/"
- Change the build type conditions and variables to suit your need. We at @ixigo have two apps(Trains and Flights) and two versions, so 4 variants in total.Use
ar
- Release orad
- Debug if you have a single app project.module
is the app in a multimodule project remove it if you have a single app.buildcmd
is the argument following./gradlew
, change it as per your project, flavors, and requirement. Lastly,apkpath
is the path from which to extract generated apks.
if [ "$1" == "tr" ]
then
module="ixigo-train-app"
buildCmd=":ixigo-train-app:assembleRelease"
apkPath="ixigo-train-app/build/outputs/apk/release"
elif [ "$1" == "td" ]
then
- Login to build server
ssh username@IP_ADDRESS_OF_BUILD_SERVER
- input password
password: zxcv
- Sample command to build
./build_android.sh *apk_type* *branch* -m "@CTO @CEO Please check out this build" -u "Alankar"
branch - Branch you want to build. Ex release_ixigo_app_4.0.8 or origin/release_ixigo_app_4.0.8.
apk_type = tr - Train Release, td - Train Debug, fr - Flight Release, fd - Flight Debug. Use as per your own project here.
[Optional] -l
as the third argument to disable posting to slack.
[Optional] -M
or -m
or --message
Custom post-build message to be sent after the apks are published. Feel free to add slack handles of channel and users here
[Optional] -u
or -U
or --user
User triggering the build. Good practice to know who sent the post-build message. Feel free to enforce this if Authors are skipping it 😉
-
In case the build system is busy you get a message like:
Another user is using the gradleDaemon, do you want to automatically build once they are done (Y/N)?
. Entery
orY
and your build will be queued once the build system is free (please do not close the terminal ). -
Upon completion builds will be immediately posted over to this channel with File name as apk name (if
-l
is not provided).
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
I am not an expert in bash. I just learned bash in order to write this script so there may be optimizations which I have missed. If that is the case feel free to add a comment or send an MR 🙏.
We use it everyday at ixigo and it definitely have made our life easier. Even our PM's can now trigger builds if you tell them the branch name 😛
I think it's best to be used in a small to medium scale enterprise where while developing apps there are many things that developers need to take care of because they are a part of the Android Team. 💻 Sharing timely builds to an internal QA team. Sharing build with Project managers and Design team for review. Sharing builds with your CEOs and CTOs (they better not have bugs). Sharing with third parties…. and the list goes on.
If you think this helped you in any way do let me know. Optimizing and adding more features to this in a never-ending process.