Unity – Install and run an APK on all connected devices with a bash script on OS X

Désolé, cet article est seulement disponible en English.

Hey,

As a mobile game developer you need to deploy your game on multiple devices, especially on Android devices.

Unity can only Build and run on ONE device.

If you connect several devices the build will be run on one device only.

So if you want to install and run an .apk file on all connected devices you can use this script:

  • Create a file named push_apk_all_devices.sh
  • Copy and paste this script:
#!/bin/bash

# 1. Set up these constants
# 2. Launch the Shell script with: "sh push_apk_all_devices.sh" in a terminal window

APK_PATH='/Users/Path/MyGame.apk'
BUNDLE_ID='com.domain.appname'
MAIN_ACTIVITY='com.unity3d.player.UnityPlayerActivity'


echo "APK_PATH: $APK_PATH"
echo "BUNDLE_ID: $BUNDLE_ID"
echo "MAIN_ACTIVITY: $MAIN_ACTIVITY"

install_to_device() {
  local prettyName=$(adb -s $1 shell getprop ro.product.model)
  echo "
  Starting Installatroning on $prettyName"
  adb -s $1 install -r "${APK_PATH}"
  adb -s $1 shell am start -n "${BUNDLE_ID}/${MAIN_ACTIVITY}"
  adb -s $1 shell input keyevent KEYCODE_WAKEUP
  echo "------> Installatron completed on $prettyName"
}
echo "----------------------- INSTALLATION-------------------------"

adb devices -l

for SERIAL in $(adb devices | tail -n +2 | cut -sf 1);
do 
  install_to_device $SERIAL&
done

exit
  • First, you need to install the Android SDK
  • Open a Terminal window
  • Type adb and Press enter in order to check if the adb command is installed
MacBook-Pro-de-Benoit-2:~ Benoit$ adb
Android Debug Bridge version 1.0.39
Revision 3db08f2c6889-android
Installed as /Users/Benoit/Library/Android/sdk/platform-tools/adb
  • Check if the devices are connected and type adb devices
MacBook-Pro-de-Benoit-2:~ Benoit$ adb devices
List of devices attached
TA39502ZNO	device
05dedc95146756a1	device
  • Build an .apk file with Unity
  • Then launch this script: sh path/push_apk_all_devices.sh (just drag and drop the script in the terminal window)
  • When it’s done press CTRL + C to stop the script.

SOURCE: https://stackoverflow.com/questions/8610733/how-can-i-adb-install-an-apk-to-multiple-connected-devices/14822827