How to set up a Fastlane Gymfile and multiple provisioning profiles

Something that has come up a number of times are questions around supporting multiple provisioning profiles. We have finally made this available (along with more customization of the Xcode build process in Xcode 9+). Longer term, we are working on simplifying the process around supporting multiple provisioning profiles since it’s a common use case, but I wanted to provide this example for others who might want to modify the Xcode build process that runs in Unity Cloud Build in some way.

As some background, Unity Cloud Build relies on Fastlane for building Xcode projects (at least for Xcode 9+), so what is being added here is the ability to customize the Fastlane process when building in Unity Cloud Build. All of the configuration options are going to be very specific to Fastlane, so some basic familiarity with the toolset is helpful.

The easiest way to describe what is available is probably by providing a basic example of how you might configure your project to build with multiple profiles currently. The following example assumes you are building an app with an application identifier of “com.unity3d.cloudbuild.base” and a stickers extension with an app identifier of “com.unity3d.cloudbuild.base.stickers”.

This setup currently requires adding three extra files to your repository:

  1. A JSON options file that controls the paths to your custom Fastfile/Gymfile and which lanes in the Fastfile should be run. This file can be placed wherever you want in the repo, but is placed at Assets/ucb_xcode_fastlane.json in this example. Supports the following properties (all of which are optional):
  • fastfile - a path to your custom Fastfile, relative to the root of your repository.

  • gymfile - a path to your custom Gymfile, relative to the root of your repository.

  • lanes - lanes within the Fastfile referenced above.

  • pre_build - lane to run before the actual Xcode build steps.

  • post_build - lane to run after the actual Xcode build steps.

Example “Assets/ucb_xcode_fastlane.json”:

{
    "fastfile": "Assets/ucb/Fastfile",
    "gymfile": "Assets/ucb/Gymfile",
    "lanes": {
        "pre_build": "use_stickers_profile",
        "post_build": ""
    }
}
  1. A custom Fastfile to install the provisioning profile and update the provisioning settings in the Xcode project. This file can be placed wherever you want in the repo, but it needs to match the path of the “fastfile” specified in ucb_xcode_fastlane.json above.

If you’ve configured pre_build/post_build lanes, an options hash is passed to those lanes when they run containing:

  • project_dir - root of the repo this project is building from.
  • build_target - build target identifier for this build.
  • output_directory - final output directory where the Xcode project will build to.

In this example, we are installing the provisioning profile at “Assets/ucb/Stickers.mobileprovision” in the repo, and updating the “Unity-iPhone-Stickers” target in the Xcode project to use that profile.

Example “Assets/ucb/Fastfile”:

lane :use_stickers_profile do |options|
    profile_path = File.join(options[:project_dir], 'Assets/ucb/Stickers.mobileprovision')
    FastlaneCore::ProvisioningProfile.install(profile_path)
    update_project_provisioning(
        xcodeproj: 'Unity-iPhone.xcodeproj',
        target_filter: 'Unity-iPhone-Stickers',
        profile: profile_path
    )
end
  1. A custom Gymfile to define the application identifier to provisioning profile mapping as part of customizing the export options. This file can be placed wherever you want in the repo, but it needs to match the path of the “gymfile” in ucb_xcode_fastlane.json above. For available options, see the fastlane docs.

In this example, we are specifying that the “com.unity3d.cloudbuild.base.stickers” application identifier should map to a UUID of “1e33640e-9a55-4357-a632-ca6c48a53a96” (which is the UUID of the provisioning profile at “Assets/ucb/Stickers.mobileprovision”).

Example “Assets/ucb/Gymfile”:

export_options(
    provisioningProfiles: {
        "com.unity3d.cloudbuild.base.stickers" => "1e33640e-9a55-4357-a632-ca6c48a53a96"
    }
)

All that’s left is to update the Advanced Settings for your build target in the dashboard. Navigate to the iOS build target in the developer dashboard under “Config” and select “Edit Advanced Options” for the corresponding iOS build target. The option is called “Custom Fastlane Configuration Path”, which is the path relative to the root of the project. In this example, you would set that as "Assets/ucb_xcode_fastlane.json".

And that’s it. Again, longer term we are working to simplify this process and make more of the Fastlane process customizable so if there is something specifically you want to see here please let us know.

  • Edited 3/22/19 to reflect updated workflow.
6 Likes

Hey @dannyd ,

Thanks for releasing this so we can get multiple provisioning profiles for iOS builds in Cloud Build.

Now for the annoying part, I’ve followed the instructions above in a Unity project using the agens plugin and seem to be getting a Check Dependencies error. Further down, we also get the error

From everything I have read up for fastlane and gym, it should be using the correct Provisioning Profile with the same development team as the one for our game as well.

I have attached a couple of images of what Cloud Build is reporting.

I have censored all the personal data from this image, but from my understanding, I am using the correct provisioning profiles, mapping them to the correct AppId and UUID. The correct Team_ID is also being used according to the codesign_identity.

Is there any help or things you can see which would be causing the error shown in the attached images?

Thanks,

hba

@hba_infinity - In general, that would suggest that target is set to use automatic signing rather than manual. We try to forcibly override all targets to use manual signing for this exact reason. Looking at your build log, it appears that you are running an “update_project_team” step in your custom lane - you almost certainly do NOT want that in there. Having the development team set is only relevant when using automatic signing.

@dannyd Apologies about that, those screenshots were taken when playing around with Fastlane and attempting to get this to work. The original attempt definitely did not have “update_project_team” line in there, but still produced the same outcome.

From my understanding, from this first attempt, we were only using Automatic Signing, and our sticker pack is also using only Automatic Signing.

Screenshot of our Unity Player Settings Identification area.
3603797--292696--StickersError5.JPG.png

Screenshot of our Sticker Pack and using Automatic Signing
3603797--292695--StickersError4.JPG.png

@hba_infinity - I probably wasn’t clear enough above. Unity Cloud Build can ONLY support manual signing (automatic signing would require being logged in to your Apple account which we obviously do not have credentials for). What does your “use_stickers_profile” lane look like? Does the profile being used for signing the stickers extension rely on the same certificate as the profile used to sign the app?

@dannyd , I’ve double checked and the profile being used is the same one for both our main application and for the stickers.

The project xcode project file, .mobileprovision, and sticker names are (from everything I can see) correct, and seem to be linking up correctly.

The Gymfile looks exactly like the example posted, but with the Application Identifier and UUID changed to be our personal values. The ucb_xcode_fastlane.json file also looks exactly like the one provided, but the Fastfile and Gymfile are located inside the same Assets/Editor/iOS/Fastlane folder as the mobileprovision.

@hba_infinity sorry for the slow response. I would uncheck “automatic signing” in the sticker pack for now. Will look for a proper fix and follow back up.

@hba_infinity - try adding this after the “update_project_provisioning” step in your custom lane:

Hey @dannyd ,

It seems like adding the ‘disable_automatic_code_signing(path: ‘Unity-iPhone.xcodeproj’)’ line seemed to fix the problem. Our Cloud Build is now set up and can build with stickers on iOS with the provided Provisioning Profile.

Thanks for all the help, and we appreciate the work you and the rest of the Unity team is doing to get all these awesome features available in a not-so-painful way!

Hey @dannyd ,

Apologies to bother again, but it seems there is another roadblock with adding Stickers to our project. This time it is during the submission process where we are getting the error

From everything I can tell from Cloud Build, the Stickers pack is being Signed and Built correctly, although now it seems they are not being added to the final IPA.

Any help on this matter would be appreciated.

Hey @dannyd ,

Just thought I would provide some more information about the problem mentioned above. From what I can tell by exploring the ipa file from our built game with Stickers, it looks like Stickers are being included into the build and are signed correctly, the only problem is that the MessagesApplicationExtensionSupport folder inside the ipa is empty, to which I am not sure what should be added into there using Fastlane or Cloud Build.

Here are some images of the structure of our ipa file -

This is the folder structure of the main directory of the ipa folder. MessagesApplicationExtensionSupport folder is located here and is in the correct directory -
3719875--307831--ipaDirectory.JPG

Unfortunately, there are no files inside the MessagesApplicationExtensionSupport folder.

Just exploring the ipa, the Unity-iPhone-Stickers project has been built into the project using all the information we provided from the information in the original posts.

Any help on this issue would be appreciated.

Thanks,

hba

@hba_infinity - sorry for the slow response, I’ve been out of the office on leave (and am still out for a few weeks so unlikely to respond very quickly). I don’t really have any more insight into what’s going on there. Are you able to produce a working binary locally when manually archiving through Xcode? Might also be worth checking with the author of the plugin to see if they have any additional insight as they are likely much more familiar with the stickers process and potential pitfalls.

всем привет, подскажите пожалуйста как мне к установленной Unity добавить еще одну платформу для сборки, которую ранее я посчитал не нужной скачивать

@dannyd - I ended up finding out what the problem was, it wasn’t anything on the Unity Cloud Build side and was actually a bug in the Stickers plugin we were using. I’ve got the creators of that plugin to fix it, so hopefully it is all aok on their end. Once that was updated, the build looked to have everything in order. Now to go through the iTunes Connect side of things again to face the next (inevitable) problem.

Thanks for your help.

Hello,
Thank you for this thread, we are edging ever-closer to making use of UCB. We are now able to sign a sticker extension target in Xcode using UCB. Here a summary of issues and fixes. Hopefully it can help others.

Initial setup
-We are able to manually code-sign in a locally built project.
-Auto-Signing is marked as off in Unity Proj settings. Profiles build fine on a manually signed local build (no scripts used for signing, needs manual adjusting).
-Our target XCode version is 9.4. The Unity version used for the project is 2018.1.9f2, UCB is set to use the latest of 2018.1

Fix 1

Fix 2

Fix 3

Useful information can also be gathered from fastlane and gym forums that deal with XCode builds and auto-code signing but are not directly related to unity Cloud Build.

Hope this helps,
Thomas

PS: it has also been an ordeal to post this message. The Forum keeps telling me that I am posting spam and the rules are not clear. Therefore some errors above are posted as keywords.

@dannyd Our project build started failing for because it thinks I provided custom fastlane config. But in logs it provides empty path for that. It started happening after I added first CUSTOM_DEFINES. Log below. I’m signing with AppStore key if it helps in any way.

Logs

3969: + Building with Xcode 10.1
3970: /BUILD_PATH/.rvm/gems/ruby-2.1.1/gems/fastimage-2.1.3/lib/fastimage.rb:68: warning: already initialized constant URI::smile:EFAULT_PARSER
3971: /BUILD_PATH/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/uri/common.rb:545: warning: previous definition of DEFAULT_PARSER was here
3972: Sending anonymous analytics information
3973: Learn more at https://docs.fastlane.tools/#metrics
3974: No personal or sensitive data is sent.
3975: You can disable this by adding `opt_out_usage` at the top of your Fastfile
3976: ----------------------------------------
3977: --- Step: Verifying fastlane version ---
3978: ----------------------------------------
3979: Your fastlane version 2.102.0 matches the minimum requirement of 2.0.0  ✅
3980: ------------------------------
3981: --- Step: default_platform ---
3982: ------------------------------
3983: Driving the lane 'ios build'
3984: Found user UCB fastlane options at
3985: +------------------+-----------+
3986: |         Lane Context         |
3987: +------------------+-----------+
3988: | DEFAULT_PLATFORM | ios       |
3989: | PLATFORM_NAME    | ios       |
3990: | LANE_NAME        | ios build |
3991: +------------------+-----------+
3992: Error in your Fastfile at line 62
3993:     60:        if user_fastlane_options_path && File.exists?(user_fastlane_options_path)
3994:     61:          puts "Found user UCB fastlane options at #{user_fastlane_options_filename}"
3995:  => 62:          user_fastlane_options = JSON.parse(File.read(user_fastlane_options_path))
3996:     63:          target_id = options[:build_target]
3997:     64:          if user_fastlane_options.has_key? target_id
3998: Is a directory @ io_fread - /BUILD_PATH/learn-teach-explore.shapes-labs.appstore-ios/
3999: +------+----------------------------+-------------+
4000: |                fastlane summary                 |
4001: +------+----------------------------+-------------+
4002: | Step | Action                     | Time (in s) |
4003: +------+----------------------------+-------------+
4004: | 1    | Verifying fastlane version | 0           |
4005: | 2    | default_platform           | 0           |
4006: +------+----------------------------+-------------+
4007: fastlane finished with errors
4008: Fastfile:62:in `read': [!] Is a directory @ io_fread - /BUILD_PATH/learn-teach-explore.shapes-labs.appstore-ios/ (Errno::EISDIR)
4009:     from Fastfile:62:in `block (2 levels) in parsing_binding'
4010:     from /BUILD_PATH/.rvm/gems/ruby-2.1.1/gems/fastlane-2.102.0/fastlane/lib/fastlane/lane.rb:33:in `call'
4011:     from /BUILD_PATH/.rvm/gems/ruby-2.1.1/gems/fastlane-2.102.0/fastlane/lib/fastlane/lane.rb:33:in `call'
4012:     from /BUILD_PATH/.rvm/gems/ruby-2.1.1/gems/fastlane-2.102.0/fastlane/lib/fastlane/runner.rb:49:in `block in execute'

I created a new config that is exactly the same as the last one and it built the project without any issues. So it looks like it saved an empty string as an config or a space or something like that.

@vrobel-lte Can you submit a support ticket for that project? That issue should have been resolved yesterday.

1 Like

Just stumbled across this awesome new feature since I recently updated.
Thank you for this possibility!

If I understand correctly, we need to push the provisioning profiles with our repository? Is it somewhere considered to make it more safe?

I like to know is it possible to use this feature (costum prebuild process) to change Info.Plist. Like

lane :handle_info_plist do
set_info_plist_value(
path: “Info.plist”,
key: “NSAppTransportSecurity”,
subkey: “NSAllowsArbitraryLoadsInWebContent”,
value: false
)
end

and if it’s possible to use upload_to_testflight in the post build process ?