Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved Unity Cloud Build - Firebase Distribution (Windows Server)

Discussion in 'Unity Build Automation' started by ArnauKokoro, Jan 27, 2022.

  1. ArnauKokoro

    ArnauKokoro

    Joined:
    Apr 27, 2021
    Posts:
    42
    Hi guys,

    After trying several ways to upload app to Firebase Distribution after built (having .apk generated). Finally find out how to upload to Firebase Distribution (at least for Windows Server and Android).

    I took this post as a first step: https://blog.kakeragames.com/2019/11/03/firebase-app-distribution-with-unity-cloud-build.html, but I had to change it and simplify it to make it work.

    ATTENTION: As finally I had to install firebase-tools globally, there is no need for package.json. You can install firebase-tool globablly in your local also to exec "firebase login:ci" to obtain the token

    Code (CSharp):
    1. #!/bin/sh
    2.  
    3. npm install -g firebase-tools
    4.  
    5. path=$(cygpath -w "$UNITY_PLAYER_PATH")
    6.  
    7. firebase appdistribution:distribute "$path" --token "$FIREBASE_TOKEN" --app "$FIREBASE_APP" --groups "$FIREBASE_GROUPS"
     
    Last edited: Jan 27, 2022
  2. ArnauKokoro

    ArnauKokoro

    Joined:
    Apr 27, 2021
    Posts:
    42
    To upload .ipa (iOS) I had to change it a bit because UCB uses Mac OS. This is more likely the one on the post I pinned:


    Code (CSharp):
    1. #!/bin/sh
    2.  
    3. npm install firebase-tools
    4.  
    5. path="$WORKSPACE/.build/last/$TARGET_NAME/build.ipa"
    6.  
    7. $(npm bin)/firebase appdistribution:distribute $path --token "$FIREBASE_TOKEN" --app "$FIREBASE_APP" --groups "$FIREBASE_GROUPS"
     
  3. starikcetin

    starikcetin

    Joined:
    Dec 7, 2017
    Posts:
    335
    At the end, I settled with this script. Handles both Android and iOS.
    Code (csharp):
    1. #!/bin/sh
    2.  
    3. git_branch=$(git branch --show-current)
    4.  
    5. # check if cygpath command exists
    6. if [ -x "$(command -v cygpath)" ]; then
    7.     # we have cygpath, we are in a windows environment. convert the path to windows path.
    8.     unity_player_path_final=$(cygpath -w "${UNITY_PLAYER_PATH}")
    9. else
    10.     # no cygpath, we are in a unix environment. no need to convert the path.
    11.     unity_player_path_final=${UNITY_PLAYER_PATH}
    12. fi
    13.  
    14. # install firebase-tools via npm
    15. npm install -g firebase-tools
    16.  
    17. # upload to firebase app distribution
    18. firebase appdistribution:distribute "${unity_player_path_final}" --token "${FIREBASE_TOKEN}" --app "${FIREBASE_APP}" --groups "${FIREBASE_GROUPS}" --release-notes "${git_branch} ${UCB_BUILD_NUMBER} ${BUILD_REVISION}"
     
    Last edited: Jul 22, 2022
    ArnauKokoro likes this.
  4. Fangh

    Fangh

    Joined:
    Apr 19, 2013
    Posts:
    245
    How do you configure Unity Cloud Build to launch this script ?
     
  5. ArnauKokoro

    ArnauKokoro

    Joined:
    Apr 27, 2021
    Posts:
    42
    There is a Post Build Script field on each UCB Target Config where you can set the name of the bash script (having it on the project root directory) you want to execute after a build is done.
     
    starikcetin likes this.
  6. starikcetin

    starikcetin

    Joined:
    Dec 7, 2017
    Posts:
    335
    It doesn't have to be at the root, you can give it a relative path too. Eg:
    scripts/unity_cloud_build/post_build.sh


    Also, the variables that are used but not declared in the script (such as
    FIREBASE_TOKEN
    ) are declared in the target config as well, under Advanced Settings > Environment variables.
     
    Last edited: Feb 4, 2023
  7. Fangh

    Fangh

    Joined:
    Apr 19, 2013
    Posts:
    245
    Hello. I succeded to do it.
    Getting the token was not easy. I had to launch firebase CLI authenticate on my mac before.

    However, the scripts tells me that
    > Authenticating with `--token` is deprecated and will be removed in a future major version of `firebase-tools`. Instead, use a service account key with `GOOGLE_APPLICATION_CREDENTIALS`: https://cloud.google.com/docs/authentication/getting-started

    and it seems that it will be effective at the 31 March 2023.

    I followed the doc but I did not understand what should I do.

    Someone has an idea ? Thank you