3

I'm using Fastlane match and gym for building and distributing my app from a CI (Bitrise) to Fabric. My Xcode settings are set to manual with a Release configuration using the AdHoc profile as described in the Fastlane docs

Now I want to distribute to the Appstore from the CI but it fails because Xcode Release config is set to use the AdHoc profile and Match installed the AppStore profile.

+---------------------------------------------------------------+-----------------------------------------------------------------------------+
|                                                           Summary for gym 2.112.0                                                           |
+---------------------------------------------------------------+-----------------------------------------------------------------------------+
| scheme                                                        | AeroNavMap                                                                  |
| export_method                                                 | app-store                                                                   |
| export_xcargs                                                 | -allowProvisioningUpdates                                                   |
| export_options.provisioningProfiles.net.tequilaapps.airnavmap | match AppStore net.tequilaapps.airnavmap                                    |
| workspace                                                     | ./PEMap.xcworkspace                                                         |
| destination                                                   | generic/platform=iOS                                                        |
| output_name                                                   | AeroNavMap                                                                  |
| build_path                                                    | /Users/vagrant/Library/Developer/Xcode/Archives/2019-01-06                  |
| clean                                                         | false                                                                       |
| output_directory                                              | .                                                                           |
| silent                                                        | false                                                                       |
| skip_package_ipa                                              | false                                                                       |
| result_bundle                                                 | false                                                                       |
| buildlog_path                                                 | /var/folders/90/5stft2v13fb_m_gv3c8x9nwc0000gn/T/fastlane_logs957341986/gym |
| skip_profile_detection                                        | false                                                                       |
| xcode_path                                                    | /Applications/Xcode.app                                                     |
+---------------------------------------------------------------+-----------------------------------------------------------------------------+
[13:47:38]: $ set -o pipefail && xcodebuild -workspace ./PEMap.xcworkspace -scheme AeroNavMap -destination 'generic/platform=iOS' -archivePath /Users/vagrant/Library/Developer/Xcode/Archives/2019-01-06/AeroNavMap\ 2019-01-06\ 13.47.38.xcarchive archive | tee /var/folders/90/5stft2v13fb_m_gv3c8x9nwc0000gn/T/fastlane_logs957341986/gym/AeroNavMap-AeroNavMap.log | xcpretty
[13:47:42]: ▸ ❌  error: No profile for team 'XXXXXXXX' matching 'match AdHoc net.tequilaapps.airnavmap' found: Xcode couldn't find any provisioning profiles matching 'G9MA9G2SST/match AdHoc net.tequilaapps.airnavmap'. Install the profile (by dragging and dropping it onto Xcode's dock item) or select a different one in the General tab of the target editor. (in target 'AeroNavMap')
[13:47:42]: ▸ ** ARCHIVE FAILED *

This all makes sense but the question is how am I supposed to setup Xcode so that I can have two Fastlane lanes, one for building for AppStore, the other for AdHoc.

I could create a new Xcode config AppStore where I'd set the AppStore provisioning profile but this rises an other issue where my custom Frameworks don't build. Similar to this question. I have many custom Frameworks and I would need to create that same AppStore configuration in their Xcode project as well but that is too much of a hack solution.

I tried forcing gym to use the AppStore profile as follows but that does not help. The AdHoc profile set in Xcode is still being used.

  desc "Builds the app for the AppStore"
  lane :build_appstore do
      match(type: "appstore", readonly: true)
      build_app(
          scheme: "AeroNavMap",
          export_method: "app-store", 
          skip_profile_detection: true,
          export_options: { provisioningProfiles: { "net.tequilaapps.airnavmap" => "match AppStore net.tequilaapps.airnavmap"}}
          )
  end

My current solution is to manually update the xcodeproj just before building but this is also not very clean

  lane :build_appstore do
      match(type: "appstore", readonly: true)
      if Helper.ci? 
        UI.message "Patching Xcode proj to use AppStore profile"
        `sed -i.bak -e 's/match AdHoc net.tequilaapps.airnavmap/match AppStore net.tequilaapps.airnavmap/g' ../PEMap/PEMap.xcodeproj/project.pbxproj`
      end
      build_app(scheme: "AeroNavMap", export_method: "app-store")
  end
Jan
  • 7,444
  • 9
  • 50
  • 74

1 Answers1

6

There are two code signing phases when you archive a build (using Xcode or gym): the code signing identity used when building (in Xcode that's what set in the build settings of your target) and the one used when exporting the archive (the one you select in the export dialog from the organizer when exporting the archive via Xcode manually)

What we do in our Fastfiles is set both to the same value when invoking gym. We override the build settings using xcargs and use there the same signing as the one we set in export_options:

MY_APP_ID = "com.foo.bar"
MY_PROFILE = "match AppStore com.foo.bar"
MY_TEAM = …

match(
    app_identifier: MY_APP_ID,
    type: "appstore",
    readonly: true
)

settings_to_override = {
  :BUNDLE_IDENTIFIER => MY_APP_ID,
  :PROVISIONING_PROFILE_SPECIFIER => MY_PROFILE,
  :DEVELOPMENT_TEAM => MY_TEAM
}

gym(
    workspace: WORKSPACE_PATH,
    scheme: "Foo",
    configuration: "Production",
    xcargs: settings_to_override,
    export_method: "app-store",
    export_options: {
        provisioningProfiles: { 
            MY_APP_ID => MY_PROFILE
        }
    }
)

Credit to https://github.com/AliSoftware

real_kappa_guy
  • 313
  • 1
  • 4
  • 12