We can all agree that having a tool to automate app builds, distributions and even analytics can be quite nice. Well, this is exactly what AppCenter does. And more.
For those of us who use GitLab as their main Git server, it can be quite frustrating setting up GitLab to work with AppCenter. We also don’t want to push our app secrets to our Git server, whether it’s our Firebase JSON or the AppCenter secrets.
In order to make AppCenter work "with" GitLab, we first have to mirror our repository to BitBucket. So go ahead and create a repository in BitBucket, then go to your user's
Settings (not repo settings, and we're still in BitBucket), create a new app password under
App passwords with all available permissions, and copy the password you are given for later.
Then go to GitLab,
Repository, and under
Mirroring Repositories, enter your BitBucket clone URL, choose
Password as auth method, and paste in the password you've been given in BitBucket. Click
Mirror Repository and you should see a new row in the table below. Click the refresh button on the right to start syncing.
That was the easy part. We still need to configure our builds and hide some secrets 😎
Go to AppCenter, and create a user if you don't already have one. Create your apps (For me it was one for Android and one for iOS) and complete the steps to add App Center’s SDK. Now go to
Build, and select
Select a Service. Select your newly created repo, and then you should see all of your branches.
Now in order for AppCenter to build your application, it needs the app's AppCenter secret (which you are given in settings, shown above), and if you use Firebase like me, it also needs the
google-services.json file (for Android) and
GoogleService-Info.plist for iOS. So what we need to do is to inject them before the build…. Let's write some code!
Our file will be called
appcenter-pre-build.sh(so AppCenter can recognise and run it before building):
echo "Injecting secrets..." echo "Updating Google JSON" echo $GOOGLE_SERVICES_JSON | base64 --decode > "$APPCENTER_SOURCE_DIRECTORY/android/app/google-services.json" echo "Updating Google plist" echo $GOOGLE_SERVICES_PLIST | base64 --decode > "$APPCENTER_SOURCE_DIRECTORY/ios/GoogleService-Info.plist" echo "Updating android secret" echo $ANDROID_SECRET > "$APPCENTER_SOURCE_DIRECTORY/android/app/src/main/assets/appcenter-config.json" echo "Updating iOS secret" echo $IOS_SECRET > "$APPCENTER_SOURCE_DIRECTORY/ios/Glitz/AppCenter-Config.plist" echo "Finished injecting secrets."
This code is for both platforms, you can edit it how you like.
Now the last thing there is to do is to insert the environment variables!
As our code shows, we have 4 environment variables. Let's go to the build configuration again, expand
Environment Variables, and add our 4 variables:
(You can use this site)