Skip to content

Commit

Permalink
Handle multiple devices connected
Browse files Browse the repository at this point in the history
  • Loading branch information
igorcferreira committed Mar 17, 2022
1 parent 7ca406a commit f99e1df
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ This is a set of processes that allows to install an AAB into a device or emulat

#### Simple usage (debug keystore):

To install an AAB into the connected device, signing the generated APK with the device debug keystore, just run:

```sh
./install-aab --bundle my-app.aab
```

#### Signed APK usage:

If you need to sign the generate APK with a specific keystore, please use the extended configuration:

```sh
./install-aab --bundle ~/Downloads/app-fw-release.aab \
--key ~/.android/debug.keystore \
Expand All @@ -20,6 +24,14 @@ This is a set of processes that allows to install an AAB into a device or emulat
--alias-password android
```

### Multiple devices connected:

If you have multiple devices connected to the machine, please specify the device id with the parameter `--device-id`. If the device id is not set, the install will fail.

```sh
./install-aab --bundle my-app.aab --device-id emulator-5554
```

### Full help text

```
Expand All @@ -33,6 +45,7 @@ Parameters:
--alias -a : Key alias
--alias-password -ap: Alias password (optional)
--help -h : Prints this helper message
--device-id : Id of the device where the APK will be installed (optional)
Keystore:
If all the key configuration is passed, the provided keystore will be used to sign the application. Otherwise, debug keystore is used.
Expand Down
13 changes: 11 additions & 2 deletions install-aab
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ KEYSTORE_FILE=""
KEYSTORE_PASSWORD=""
ALIAS=""
ALIAS_PASSWORD=""
DEVICE_ID=""

function print_help {
echo "Usage:"
Expand All @@ -21,6 +22,7 @@ function print_help {
echo " --alias -a : Key alias"
echo " --alias-password -ap: Alias password (optional)"
echo " --help -h : Prints this helper message"
echo " --device-id : Id of the device where the APK will be installed (optional)"
echo ""
echo "Keystore:"
echo " If all the key configuration is passed, the provided keystore will be used to sign the application. Otherwise, debug keystore is used."
Expand All @@ -34,6 +36,7 @@ function print_environment {
echo " adb : $(which adb)"
echo " bundletool: $(which bundletool)"
echo " keystore : ${KEYSTORE_FILE}"
echo " device id : ${DEVICE_ID}"
}

function command_exists {
Expand Down Expand Up @@ -95,6 +98,7 @@ while [ -n "$1" ]; do
--key-password | -kp) KEYSTORE_PASSWORD="$2" && shift ;;
--alias | -a) ALIAS="$2" && shift ;;
--alias-password | -ap) ALIAS_PASSWORD="$2" && shift ;;
--device-id) DEVICE_ID="$2" && shift ;;
esac
shift
done
Expand Down Expand Up @@ -137,10 +141,15 @@ else
echo "No valid keystore configuration provided. Using debug keystore"
fi

bundletool "build-apks" "--connected-device" "--overwrite" "--bundle=${AAB_FILE}" "--output=${TEMP_PATH}" $KEY_INFO
DEVICE_INFO=""
if [[ ! -z "${DEVICE_ID}" ]]; then
DEVICE_INFO="--device-id ${DEVICE_ID}"
fi

bundletool "build-apks" "--connected-device" $DEVICE_INFO "--overwrite" "--bundle=${AAB_FILE}" "--output=${TEMP_PATH}" $KEY_INFO

echo "Installing APK"
bundletool "install-apks" "--apks=${TEMP_PATH}"
bundletool "install-apks" "--apks=${TEMP_PATH}" $DEVICE_INFO

if [[ -f "${TEMP_PATH}" ]]; then
rm "${TEMP_PATH}"
Expand Down

0 comments on commit f99e1df

Please sign in to comment.