Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiplatform iOS builds #21319

Merged
merged 5 commits into from Oct 7, 2023

Conversation

zachwaugh
Copy link
Contributor

@zachwaugh zachwaugh commented Jun 4, 2023

Checklist

  • I've run bundle exec rspec from the root directory to see all new and existing tests pass
  • I've followed the fastlane code style and run bundle exec rubocop -a to ensure the code style is valid
  • I see several green ci/circleci builds in the "All checks have passed" section of my PR (connect CircleCI to GitHub if not)
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary.

Motivation and Context

Currently using a multiplatform Xcode project (Xcode > New Project > Multiplatform App) will fail to build for iOS from fastlane using build_app with a PKG invalid error. The reason is the platform check for whether to do an iOS build Gym.building_for_ios? returns false, so it attempts to build an iOS app like a macOS app.

Description

This fixes the above error by explicitly checking for cases where we might be a multiplatform app (e.g. multiple SUPPORTED_PLATFORM properties) and checking which sdk is being used. I'm not sure if this is the correct fix, I couldn't find good documentation on the right way to choose a platform to build for a multiplatform app using xcodebuild. Passing the sdk: "iphoneos" or sdk: "macosx" option seemed to work though, so I'm expecting that is required and what we need to check. If there is alternative way to inform xcodebuild about the platform, I'm happy to change the check.

I added a new example project created using the Multiplatform App template and some related tests. I'm not a Ruby programmer and not familiar with the codebase, so let me know if there is a better way to do any (or all) of this.

@google-cla
Copy link

google-cla bot commented Jun 4, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Ensure fastlane can parse Xcode 14 projects
@PSchmiedmayer
Copy link

@zachwaugh Thank you for creating this PR. We run into a similar issue with one of our applications, it would be great to see this supported in fastlane.

Is there a plan to merge this PR and get it into a next release @joshdholtz. Any way that we could help there?

Copy link
Collaborator

@getaaron getaaron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, it looks great!

@getaaron getaaron merged commit 72c053d into fastlane:master Oct 7, 2023
8 checks passed
@ConradoMateu
Copy link

ConradoMateu commented Nov 13, 2023

Hi @zachwaugh, thanks for your MR.

I have Fastlane and Gym 2.216.0 and I am still having the issue that you mentioned.

I am using Xcode 15.1 and Codemagic.

Here is the information

+-----------------------------------------------------------------------------------------------------------------+
| Summary for gym 2.216.0 |
+----------------------------------------------------+------------------------------------------------------------+
| scheme | Truffle |
| export_method | app-store |
| destination | generic/platform=iOS |
| sdk | iphoneos |
| export_options.provisioningProfiles.art.truffle.fm | match AppStore art.truffle.fm |
| project | ./Truffle.xcodeproj |
| clean | false |
| output_directory | . |
| output_name | Truffle |
| silent | false |
| skip_package_ipa | false |
| skip_package_pkg | false |
| build_path | /Users/builder/Library/Developer/Xcode/Archives/2023-11-13 |
| result_bundle | false |
| buildlog_path | ~/Library/Logs/gym |
| xcodebuild_formatter | xcpretty |
| build_timing_summary | false |
| skip_profile_detection | false |
| xcodebuild_command | xcodebuild |
| skip_package_dependencies_resolution | false |
| disable_package_automatic_updates | false |
| use_system_scm | false |
| xcode_path | /Applications/Xcode-15.1.app |
+----------------------------------------------------+------------------------------------------------------------+

Here is the gym lane:

  desc "Release a new version to TestFlight"
  lane :release do |options|

    create_keychain(
      name: ENV["MATCH_KEYCHAIN"],
      password: ENV["MATCH_PASSWORD"],
      default_keychain: true,
      unlock: true,
      timeout: 3600,
      add_to_search_list: true,
      verbose: true
    )
    # Fetch certificates and provisioning profiles using match
    match(type: "appstore",app_identifier: "art.truffle.fm", readonly: true, keychain_name: ENV["MATCH_KEYCHAIN"], keychain_password: ENV["MATCH_PASSWORD"]) # readonly: true is recommended for CI
    
    # Increment version and build number
    bump_and_push_version(options)
    
    # Build the IPA
    gym(
    scheme: truffle_scheme,
    export_method: 'app-store',
    destination: "generic/platform=iOS",
    sdk: "iphoneos"
    )
    
    # Define the API key for App Store Connect
    api_key = app_store_connect_api_key(
    key_id: ENV["APPSTORE_API_KEY"],
    issuer_id: ENV["APPSTORE_ISSUER_ID"],
    key_content: ENV["AUTH_KEY"],
    in_house: false # set to true for enterprise and false for individual accounts
    )
    
    # Upload to TestFlight
    pilot(
    api_key: api_key,
    ipa: lane_context[SharedValues::IPA_OUTPUT_PATH],
    skip_waiting_for_build_processing: true
    )
    
    cleanup_git_configuration
  end

Is there any workaround?

Here is the output error:

Successfully exported and compressed dSYM file
[12:35:52]: Successfully exported the .app file:
[12:35:52]: ./Truffle.app
[12:35:52]: Generated plist file with the following values:
[12:35:52]: ▸ -----------------------------------------
[12:35:52]: ▸ {
[12:35:52]: ▸ "provisioningProfiles": {
[12:35:52]: ▸ "art.truffle.fm": "match AppStore art.truffle.fm"
[12:35:52]: ▸ },
[12:35:52]: ▸ "method": "app-store",
[12:35:52]: ▸ "signingStyle": "manual"
[12:35:52]: ▸ }
[12:35:52]: ▸ -----------------------------------------
[12:35:52]: $ /usr/bin/xcrun /Users/builder/.rbenv/versions/3.0.4/lib/ruby/gems/3.0.0/gems/fastlane-2.216.0/gym/lib/assets/wrap_xcodebuild/xcbuild-safe.sh -exportArchive -exportOptionsPlist '/var/folders/w2/rrf5p87d1bbfyphxc7jdnyvh0000gn/T/gym_config20231113-1532-ezqrem.plist' -archivePath /Users/builder/Library/Developer/Xcode/Archives/2023-11-13/Truffle\ 2023-11-13\ 12.35.15.xcarchive -exportPath '/var/folders/w2/rrf5p87d1bbfyphxc7jdnyvh0000gn/T/gym_output20231113-1532-542bv5'
+-------------------------------------------------------------------------------------------+
| Lane Context |
+------------------------------------+------------------------------------------------------+
| DEFAULT_PLATFORM | ios |
| PLATFORM_NAME | ios |
| LANE_NAME | ios release |
| KEYCHAIN_PATH | ~/Library/Keychains/codemagic.keychain |
| ORIGINAL_DEFAULT_KEYCHAIN | "/Users/builder/Library/Keychains/login.keychain-db" |
| SIGH_PROFILE_TYPE | app-store |
| MATCH_PROVISIONING_PROFILE_MAPPING | {"art.truffle.fm"=>"match AppStore art.truffle.fm"} |
| VERSION_NUMBER | 1.0.29 |
| SIGH_PROFILE_PATHS | |
| DSYM_PATHS | |
| DSYM_LATEST_UPLOADED_DATE | |
| BUILD_NUMBER | 1 |
+------------------------------------+------------------------------------------------------+
[12:35:56]: PKG invalid

@zachwaugh
Copy link
Contributor Author

@ConradoMateu this PR was merged on Oct 7 and last release was Sept 18, so doesn't look like it's in a release yet, you'll need to target the master branch for now

@NachoSoto
Copy link
Contributor

I think this probably fixes #20826?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants