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:
- 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": ""
}
}
- 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
- 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.