We can all agree that having a tool that automates app builds, distributions and even analytics can be quite nice. Well, this is exactly what AppCenter does. And more.

However…

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.

BitBucket Mirroring

In order to have 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, Settings -> Repository , and under Mirroring Repositories , enter your new BitBucket repo’s clone URL, choose Push under Mirror Direction , Password as auth method, and paste the password you've been given in BitBucket. Click Mirror Repository and you should see a new row in the table just below the mirror button. Click the refresh button on the right to start syncing.

Setup AppCenter

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 AppCenter’s SDK. Now go to the Build tab , and select BitBucket under Select a Service . Select your newly created repo, and then you should see all of your branches. That's it for now.

Build Scripts

Now in order for AppCenter to build your application, it needs the app’s AppCenter secret (which you are given in the settings page, shown above) files for both iOS and Android, so go ahead and fill in the secrets in the following files (they may be already filled if you performed a react-native link):

android/app/src/main/assets/appcenter-config.json ios/YOUR_PROJECT_NAME/AppCenter-Config.plist

Now you need to add these files to your .gitignore file, and then base64 both of them in order to later insert the encoded values into your AppCenter’s build environment variables. I would also recommend adding example files for each of the ignored files (e.g appcenter-config.example.json) so there won’t be any errors creating the actual files in the pre build script.

If you use Firebase like I do, you also need to inject the google-services.json file (for Android) and GoogleService-Info.plist for iOS. First, add these files to your gitignore and as before, create empty example files for each.

Now let's write our pre build code!

Create a new file named appcenter-pre-build.sh (so AppCenter can recognise and run it before building):

This code is for both platforms, you can edit it however you like.

Now the last thing there is to do is to insert the environment variables.

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:

GOOGLE_SERVICES_JSON , GOOGLE_SERVICES_PLIST , ANDROID_SECRET , IOS_SECRET .

Make sure to base64 encode the values before entering them!

(You can use this site)