Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Continously deploy from Unity Cloud Build to Google Play Store

Tags:

Are there any deployment tools that bridges the gap between Unity Cloud Build and the Google Play Store in order to continuously deploy generated APKs to the store?

like image 579
Jay Wick Avatar asked Nov 30 '16 01:11

Jay Wick


1 Answers

This is an old question, but still very valid. I've been messing with this for a while. Used to have a ridiculously complicated bash script for this, until I realized that fastlane is installed, and you can easily use it in a bash script in the post build event. Now it's literally a 4 line script (minus comments), here it is:

#!/bin/bash

# Passed in as environment variables from CI, you must get this from Google and put
# it in the environment variable PLAYSTORE_KEY in the Unity build config.
# $PLAYSTORE_KEY - The JSON file with the credentials for the Google Developer account

# You can also just hardcode your package name, e.g. com.candycrush.game or whatever here...
PACKAGE_NAME=$(cat "$WORKSPACE/build.json" | jq -j '.[].bundleid')

# Unity environment variables replace the "\n" signs from the private key with spaces for some reason,
# so we replaces spaces with "\n" signs again so it works properly.
KEY_WITH_NEWLINES=$(echo $PLAYSTORE_KEY | jq '.private_key |= sub(" (?!PRIVATE|KEY)"; "\n"; "g")' -c -j)

# You could also use shorter argument names here, but DO NOT use -e for --release-status, there's some error there where
# fastlane thinks -e should mean the -env option and fails.
# Also, you could put the "draft" and "internal" into environment variables if you want to never have to modify the script
# again and just control it with environment variables.
fastlane supply --package_name "$PACKAGE_NAME" --aab "$UNITY_PLAYER_PATH"  --json_key_data "$KEY_WITH_NEWLINES" --release-status draft --track internal

So just put that in a "upload.sh" file, add it as the post build file in the build config. Get your google key in json format and put it in as the env variable "PLAYSTORE_KEY". No additional fastlane configuration is needed, which was a pleasant surprise, it actually works with just the right parameters passed in.

like image 112
Einar Egilsson Avatar answered Sep 24 '22 16:09

Einar Egilsson