Xcode Cloud, How to upload ipa to Firebase AppDistribution

Xcode Cloud setup for uploading IPA to Firebase App Distribution

1. Download the Firebase CLI for macOS

https://firebase.google.com/docs/cli#mac-linux-standalone-binary

2. Copy firebase-tools-macos.zip into the ci_scripts Folder

3. Create a Service Account

I suggest use Service Account instead of using token. Because firebase no longer support token. (firebase login:ci)

screenshot 2023 12 20 at 11.59.27e280afam

Document

Don’t forget to check Project before creating Service Accounts.

screenshot 2023 12 20 at 3.00.52e280afam
screenshot 2023 12 20 at 3.02.16e280afam
screenshot 2023 12 20 at 3.04.09e280afam

Once create an account, create private key at KEYS.

Put the downloaded JSON file into the ci_scripts folder and rename it to credentials.json

4. Add Environment Variables in Xcode Cloud

Add FIREBASE_APP_ID

screenshot 2023 12 20 at 1.20.09e280afpm
screenshot 2023 12 20 at 4.23.26e280afpm

[Option] ADD GOOGLE_SERVICE_ACCOUNT_KEY

You can skip this if you want to add json file into git repo. In this post, I’ll skip this step.

Open JSON (Step 3, Downloaded JSON Key), Copy all the text in JSON and Paste it.

# If you added GOOGLE_SERVICE_ACCOUNT_KEY into Xcode Cloud's Environment Variable then use this
echo "$GOOGLE_SERVICE_ACCOUNT_KEY" | jq -r '.' > credentials.json
export GOOGLE_APPLICATION_CREDENTIALS=./credentials.json

5. Edit ci_post_clone.sh in the ci_scripts Folder

Install any packages you want to use it later.

#!/bin/sh
brew install jq

6. Edit ci_post_xcodebuild.sh in the ci_scripts Folder

Document

#!/bin/zsh
upload_ipa_to_firebase() {
unzip firebase-tools-macos.zip
chmod +x ./firebase-tools-macos
local file_path="$1/$CI_PRODUCT.ipa"
echo "🚀 Upload $file_path to Firebase App ID $FIREBASE_APP_ID"
# https://firebase.google.com/docs/app-distribution/authenticate-service-account?platform=ios
export GOOGLE_APPLICATION_CREDENTIALS=./credentials.json
./firebase-tools-macos appdistribution:distribute "$file_path" --app "$FIREBASE_APP_ID"
echo "🚀 End uploading dSYMs"
}
if [[ -n "$CI_ARCHIVE_PATH" && "$CI_XCODEBUILD_EXIT_CODE" == 0 ]]; then
if [ -d "$CI_APP_STORE_SIGNED_APP_PATH" ]; then
upload_ipa_to_firebase "$CI_APP_STORE_SIGNED_APP_PATH"
elif [ -d "$CI_AD_HOC_SIGNED_APP_PATH" ]; then
upload_ipa_to_firebase "$CI_AD_HOC_SIGNED_APP_PATH"
fi
else
echo "Archive path isn't available. Unable to run dSYMs uploading script."
fi

7. Check the IPA File

Check Xcode Cloud Logs

screenshot 2023 12 20 at 4.24.10e280afpm

Check Firebase

screenshot 2023 12 20 at 4.24.45e280afpm

Conclusion

I faced a lot of issues to upload ipa file into firebase. Because firebase-tools-macos has updated and token login was deprecated.

Also Xcode Cloud doesn’t support git-lfs. That’s why I upload firebase-tools-macos.zip file and unzip it at ci_post_xcodebuild.sh. (without zip file I need to set git-lfs because this tool’s size is around 150mb)

The other option is download firebase-tool at ci_post_xcodebuild.sh.

curl -sL https://firebase.tools | bash

All options are up to you. I hope my post helps you. Thanks!

Comments

Leave a Reply

Discover more from Shawn

Subscribe now to keep reading and get access to the full archive.

Continue reading