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?
Asked
Active
Viewed 1,933 times
6

Einar Egilsson
- 3,438
- 9
- 36
- 47

Jay Wick
- 12,325
- 10
- 54
- 78
-
1i didn't find any direct linking. do share here if you find any. Indirect way is using https://github.com/fastlane/fastlane ( Create a github automation build from Unity Cloud and send it to fastlane )? – Amod Gokhale Nov 30 '16 at 13:55
1 Answers
10
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.

Dharman
- 30,962
- 25
- 85
- 135

Einar Egilsson
- 3,438
- 9
- 36
- 47
-
-
1You need to create a service account, then you get its credentials as a json file. See https://developers.google.com/android-publisher/getting_started#using_a_service_account – Einar Egilsson Dec 01 '21 at 23:08
-
thanks! I thought I had to do something with Android studio. That makes more sense. – Adam B Dec 01 '21 at 23:17
-
I had luck following these instructions for the JSON key: http://help.mystudio.io/en/articles/2687493-how-to-create-your-google-json-file-and-share-google-developer-api-access – Brian Handy Dec 06 '21 at 00:01
-
1Is the fastlane CLI already present on the build agent in UCB? No need to install it? – MEMark Dec 12 '21 at 13:29
-
1
-
-
@MEMark what do you mean? Get it how? Not just read the environment variable? – Einar Egilsson Jan 06 '22 at 16:50
-
@EinarEgilsson Oh, I didn't know there even was such an env var! (That documentation is quite poor.) Same goes for $PACKAGE_NAME then, it just exists? – MEMark Jan 06 '22 at 17:42