Skip to content

Instantly share code, notes, and snippets.

@DanielJenkyn
Last active February 12, 2024 09:00
Show Gist options
  • Save DanielJenkyn/0814229f00b9aaef99aa5f7de13eab6b to your computer and use it in GitHub Desktop.
Save DanielJenkyn/0814229f00b9aaef99aa5f7de13eab6b to your computer and use it in GitHub Desktop.
Script to install .apk and .obb (Split binary) onto Android device

This bash script was written to easily install an .apk and the matching .obb file (also know as a split binary build) on an Android device. It's basically just a wrapper for some adb commands.

Prerequisites

  • This script assumes you have adb (Android debug bridge) installed
  • This script has only been tested on macOS

How to run

  • Download this script
  • Change the project_name in the script or specify a project name with -f (See options below)
  • Place script where the .apk and .obb are located
  • cd to .apk and .obb location,type install_obb.sh
  • Huzzah!
  • Side-note - If you have multiple .apk and .obb files in the directory with the same name, the script will just take the most recent

Options

  • install_obb.sh -r - re-install the app and keep its data on the device. Off by defaut
  • install_obb.sh -f - Overwrite default project name in script

To run script globally

  • Put script in /usr/local/bin, or directory of your choice
  • Then export path to bash profile
  • echo ‘export INSTALL_OBB_SCRIPT=/usr/local/bin/install_obb.sh’ >> ~/.bash_profile
  • echo ‘export PATH=${PATH}:$INSTALL_OBB_SCRIPT >> ~/.bash_profile
  • . ~/.bash_profile
  • Now you can script from anywhere
  • Double Huzzah!

Author

  • Daniel Jenkyn
#!/bin/bash
project_name= com.jenkyncorp.bestapp
reinstall=
# Takes the most recent .apk and .obb (If you have multiple files)
OBB=$(ls -t *.obb | head -n1)
APK=$(ls -t *.apk | head -n1)
while [ "$1" != "" ]; do
case $1 in
-f | --file ) shift
project_name=$1
;;
-r | --reinstall ) reinstall=1
;;
* ) usage
exit 1
esac
shift
done
echo "Creating obb directory and pushing obb ..."
adb shell mkdir -p /sdcard/Android/obb/$project_name
adb push -p $OBB /sdcard/Android/obb/$project_name/
if [ “$reinstall” = “1” ]; then
adb install -r $APK
else
adb install $APK
fi
@markf-hutch
Copy link

Be careful not to leave the speech marks around your project name, or this won't push the obb correctly (or at least it didn't for me)

@DanielJenkyn
Copy link
Author

@markf-hutch Ha, only just seen this updated. No need for double quotes, nothing to be protected from reinterpretation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment