shorebird icon indicating copy to clipboard operation
shorebird copied to clipboard

Error on Building iOS locally and in pipeline

Open omarammarthefirst opened this issue 1 year ago โ€ข 15 comments

App ID: dcadf652-7fb4-4d26-9cd3-9b4c850ac58c

Screenshot 2024-12-18 at 12 14 42โ€ฏPM

Description We have newly integrated shorebird into our system, the release on android works amazing. however on iOS attempting to build locally or in our pipeline breaks with no clear issue. we are using flutter 3.24.5.

attached below is a copy of verbose logs from local machine and from pipeline. as well as the pipeline workflow

Steps To Reproduce locally:

  1. run fvm flutter pub get
  2. run fvm dart run build_runner build --delete-conflicting-outputs
  3. run fvm dart fvm flutter pub run intl_utils:generate
  4. run shorebird release ios --flutter-version 3.24.5 --verbose

pipeline

name: iOS Release

on:
  push:
    tags:
      - "v[0-9].[0-9]+.[0-9]+" # e.g. v1.0.0

  workflow_dispatch:

env:
  SHOREBIRD_TOKEN: ${{ secrets.SHOREBIRD_TOKEN }}
jobs: 
 release-ios:
    runs-on: macos-latest

    name: ๐ŸŽ Release iOS

    env:

    steps:
      - name: ๐Ÿ“š Git Checkout
        uses: actions/checkout@v4

      - uses: subosito/flutter-action@v2
        with:
          flutter-version: "3.24.5"
          channel: "stable"
          cache: true

      - name: flutter clean
        run: flutter clean

      - name: Get dependencies
        run: flutter pub get

      - name: Build Runner
        run: dart run build_runner build --delete-conflicting-outputs

      - name: intl generation
        run: flutter pub run intl_utils:generate

      - name: ๐Ÿฆ Setup Shorebird
        uses: shorebirdtech/setup-shorebird@v1
        with:
          cache: true

      - name: โœ๏ธ Setup XCode Signing
        env:
          CERTIFICATE: ${{ secrets.IOS_BUILD_CERTIFICATE_BASE64 }}
          CERTIFICATE_PASSWORD: ${{ secrets.IOS_BUILD_CERTIFICATE_PASSWORD }}
          PROVISIONING_PROFILE: ${{ secrets.BUILD_PROVISION_PROFILE_BASE64 }}
          KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }}
        run: |
          # create variables
          CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12
          KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db
          PP_PATH=$RUNNER_TEMP/temp.mobileprovision

          # import certificate and provisioning profile from secrets
          echo -n "$CERTIFICATE" | base64 --decode -o $CERTIFICATE_PATH
          echo -n "$PROVISIONING_PROFILE" | base64 --decode -o $PP_PATH

          # create temporary keychain
          security create-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
          security set-keychain-settings -lut 21600 $KEYCHAIN_PATH
          security unlock-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH

          # import certificate to keychain
          security import $CERTIFICATE_PATH -P "$CERTIFICATE_PASSWORD" -A -t cert -f pkcs12 -k $KEYCHAIN_PATH
          security list-keychain -d user -s $KEYCHAIN_PATH
          security find-identity -v

          # use uuid for the name of provisioning profile
          UUID=$(/usr/libexec/PlistBuddy -c "Print UUID" /dev/stdin <<< $(/usr/bin/security cms -D -i $PP_PATH))

          # apply provisioning profile
          mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles
          cp $PP_PATH ~/Library/MobileDevice/Provisioning\ Profiles/$UUID.mobileprovision

      - name: ๐Ÿš€ Shorebird Release
        uses: shorebirdtech/shorebird-release@v0
        with:
          platform: ios
          args: "--verbose --flutter-version=3.24.5"

      - name: ๐Ÿงน Clean Up
        if: ${{ always() }}
        run: |
          PP_PATH=$RUNNER_TEMP/temp.mobileprovision
          security delete-keychain $RUNNER_TEMP/app-signing.keychain-db
          rm $RUNNER_TEMP/temp.mobileprovision

      - name: ๐Ÿ“ฆ Upload Artifact
        uses: actions/upload-artifact@v4
        with:
          name: ios-release
          path: build/ios/ipa/app-release.ipa

      - name: Clean up keychain and provisioning profile
        if: ${{ always() }}
        run: |
          security delete-keychain $RUNNER_TEMP/app-signing.keychain-db
          rm ~/Library/MobileDevice/Provisioning\ Profiles/build_pp.mobileprovision

Expected Behavior

Build to be done successfully Screenshots

  1. local build results
IO  : Writing 1002116 characters to text file /Users/omarammar/.pub-cache/log/pub_log.txt.
[   +1 ms] Encountered error while archiving for device.
[        ] 
           #0      throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
           #1      _BuildIOSSubCommand.runCommand (package:flutter_tools/src/commands/build_ios.dart:722:7)
           <asynchronous suspension>
           #2      BuildIOSArchiveCommand.runCommand (package:flutter_tools/src/commands/build_ios.dart:427:50)
           <asynchronous suspension>
           #3      FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1408:27)
           <asynchronous suspension>
           #4      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
           <asynchronous suspension>
           #5      CommandRunner.runCommand (package:args/command_runner.dart:212:13)
           <asynchronous suspension>
           #6      FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:420:9)
           <asynchronous suspension>
           #7      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
           <asynchronous suspension>
           #8      FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:364:5)
           <asynchronous suspension>
           #9      run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:130:9)
           <asynchronous suspension>
           #10     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
           <asynchronous suspension>
           #11     main (package:flutter_tools/executable.dart:93:3)
           <asynchronous suspension>

  1. pipeline build results
 Writing 1000543 characters to text file /Users/runner/.pub-cache/log/pub_log.txt.
[   +2 ms] Encountered error while archiving for device.
[        ] 
           #0      throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
           #1      _BuildIOSSubCommand.runCommand (package:flutter_tools/src/commands/build_ios.dart:722:7)
           <asynchronous suspension>
           #2      BuildIOSArchiveCommand.runCommand (package:flutter_tools/src/commands/build_ios.dart:427:50)
           <asynchronous suspension>
           #3      FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1408:27)
           <asynchronous suspension>
           #4      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)

           <asynchronous suspension>
           #5      CommandRunner.runCommand (package:args/command_runner.dart:212:13)
           <asynchronous suspension>
           #6      FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:420:9)
           <asynchronous suspension>
           #7      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
           <asynchronous suspension>
           #8      FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:364:5)
           <asynchronous suspension>
           #9      run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:130:9)
           <asynchronous suspension>
           #10     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
           <asynchronous suspension>
           #11     main (package:flutter_tools/executable.dart:93:3)
           <asynchronous suspension>

 (822.1s)
[Process.run] git symbolic-ref HEAD (in /Users/runner/.shorebird/bin/cache)
Exited with code 0

stdout:
refs/heads/stable

[Process.run] git rev-parse --verify HEAD (in /Users/runner/.shorebird/bin/cache)
Exited with code 0

apologies for the text files but the output is very long pipeline_build_logs.txt local_build_logs.txt

omarammarthefirst avatar Dec 18 '24 08:12 omarammarthefirst

i have checked the following issues and following the steps in them didn't resolve the problem https://github.com/shorebirdtech/shorebird/issues/2591 https://github.com/shorebirdtech/shorebird/issues/2590

omarammarthefirst avatar Dec 18 '24 08:12 omarammarthefirst

I think we're probably not surfacing as much error output as we should be. If you run:

FLUTTER_STORAGE_BASE_URL=https://download.shorebird.dev /Users/omarammar/.shorebird/bin/cache/flutter/3faf56aafaec13a0ba54445574e8e81f3235070c/bin/flutter build ipa --release --verbose

do you see anything more helpful there?

bryanoltman avatar Dec 18 '24 15:12 bryanoltman

(filed https://github.com/shorebirdtech/shorebird/issues/2705)

bryanoltman avatar Dec 18 '24 15:12 bryanoltman

Hey @bryanoltman , This is the error thats surfacing now, I'm attaching the logs again for you to see if I missed anything

               Unhandled exception:
               Null check operator used on a null value
               #0      Context.embedFlutterFrameworks (file:///Users/omarammar/.shorebird/bin/cache/flutter/3faf56aafaec13a0ba54445574e8e81f3235070c/packages/flutter_tools/bin/xcode_backend.dart:237:68)
               #1      Context.run (file:///Users/omarammar/.shorebird/bin/cache/flutter/3faf56aafaec13a0ba54445574e8e81f3235070c/packages/flutter_tools/bin/xcode_backend.dart:61:9)
               #2      main (file:///Users/omarammar/.shorebird/bin/cache/flutter/3faf56aafaec13a0ba54445574e8e81f3235070c/packages/flutter_tools/bin/xcode_backend.dart:17:5)
               #3      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295:33)
               #4      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
               Command PhaseScriptExecution failed with a nonzero exit code

it looks like the issue is in the shorebird flutter package, for your reference, when archieving from xcode the build is done successfully

logs.txt

omarammarthefirst avatar Dec 19 '24 05:12 omarammarthefirst

Shorebird will be out for next week (US holidays). So we'd love to help, but are most likely to get back to you in a week or so. Thanks for reporting.

eseidel avatar Dec 20 '24 22:12 eseidel

We also improved our iOS error reporting in our 1.5.4 release, so trying the failing command again might give you more insights into what the issue is.

bryanoltman avatar Dec 20 '24 22:12 bryanoltman

Hey Guys, As suggested by you I have updated the shorebird to the newer release, however no new bugs ahve shown up, I have attached the logs below. @eseidel @bryanoltman

logs.txt

omarammarthefirst avatar Jan 02 '25 12:01 omarammarthefirst

Hey Guys, As suggested by you I have updated the shorebird to the newer release, however no new bugs ahve shown up, I have attached the logs below. @eseidel @bryanoltman

logs.txt

PhaseScriptExecution Thin\ Binary /Users/omarammar/Library/Developer/Xcode/DerivedData/Runner-cwupfmrpqdhpfleenkbozbodpulm/Build/Intermediates.noindex/ArchiveIntermediates/Runner/IntermediateBuildFilesPath/Runner.build/Release-iphoneos/Runner.build/Script-3B06AD1E1E4923F5004D2608.sh (in target 'Runner' from project 'Runner')
                   cd /Users/omarammar/waj/ios
                   export ACTION\=install
...
                   export variant\=normal
                   /bin/sh -c /Users/omarammar/Library/Developer/Xcode/DerivedData/Runner-cwupfmrpqdhpfleenkbozbodpulm/Build/Intermediates.noindex/ArchiveIntermediates/Runner/IntermediateBuildFilesPath/Runner.build/Release-iphoneos/Runner.build/Script-3B06AD1E1E4923F5004D2608.sh
               Unhandled exception:
               Null check operator used on a null value
               #0      Context.embedFlutterFrameworks (file:///Users/omarammar/.shorebird/bin/cache/flutter/3faf56aafaec13a0ba54445574e8e81f3235070c/packages/flutter_tools/bin/xcode_backend.dart:237:68)
               #1      Context.run (file:///Users/omarammar/.shorebird/bin/cache/flutter/3faf56aafaec13a0ba54445574e8e81f3235070c/packages/flutter_tools/bin/xcode_backend.dart:61:9)
               #2      main (file:///Users/omarammar/.shorebird/bin/cache/flutter/3faf56aafaec13a0ba54445574e8e81f3235070c/packages/flutter_tools/bin/xcode_backend.dart:17:5)
               #3      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295:33)
               #4      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
               Command PhaseScriptExecution failed with a nonzero exit code

Looks like a crash in the Flutter tool. Unclear if it's caused by shorebird or not.

eseidel avatar Jan 02 '25 16:01 eseidel

Looks like it's trying to read FLUTTER_BUILD_DIR and it's not set: https://github.com/shorebirdtech/flutter/blob/3faf56aafaec13a0ba54445574e8e81f3235070c/packages/flutter_tools/bin/xcode_backend.dart#L237

eseidel avatar Jan 02 '25 16:01 eseidel

@eseidel Is there something specific I need to do to have it set? , considering build succeeds when I use flutter build ipa and xcode archieve utility

omarammarthefirst avatar Jan 03 '25 11:01 omarammarthefirst

@eseidel Is there something specific I need to do to have it set? , considering build succeeds when I use flutter build ipa and xcode archive utility

No, you shouldn't have to set anything.

Maybe https://github.com/flutter/flutter/issues/140845 or https://stackoverflow.com/questions/77259439/my-xcode-backend-dart-file-has-errors-when-trying-to-run-my-application have an answer?

eseidel avatar Jan 03 '25 20:01 eseidel

@eseidel I have tried the approaches, changing things up and down like people in thread, it doesn't seem to change the error message, could it be because I'm building with an older flutter version (Currently using 3.24.5)?

omarammarthefirst avatar Jan 14 '25 10:01 omarammarthefirst

Were we able to get this resolved? I seem to recall we had a video call and were able to make progress, but perhaps I'm confusing issues.

eseidel avatar Nov 20 '25 20:11 eseidel

Hey @eseidel , Thanks for your attention to the matter, we didn't get a call no, I haven't tried building it through the pipeline since, 3.24.5, I most recently upgraded to 3.38.1 , I'll try it out and let you know

omarammarthefirst avatar Nov 20 '25 20:11 omarammarthefirst

Hey @eseidel , Thanks for your attention to the matter, we didn't get a call no, I haven't tried building it through the pipeline since, 3.24.5, I most recently upgraded to 3.38.1 , I'll try it out and let you know

Hey @eseidel , I have tried running it again this morning. however, due to an issue in flutter 3.38.1 mentioned here , I'm unable to test if the shorebird release is working for me, I'll wait until 3.38.2 is rolled out on shorebird then update this issue.

omarammarthefirst avatar Nov 24 '25 07:11 omarammarthefirst

I'm working on rolling out 3.38.3 right now: https://github.com/shorebirdtech/shorebird/issues/3398

eseidel avatar Nov 25 '25 00:11 eseidel

Hey @eseidel , I have ran the pipeline today on both 3.38.2 and 3.38.3. both unfortuantly failed. on checking the errors I get this error

2025-11-25T12:58:32.6607880Z              Unhandled exception:
2025-11-25T12:58:32.6608010Z              Null check operator used on a null value
2025-11-25T12:58:32.6608600Z              #0      Context._embedNativeAssets (file:///Users/runner/.shorebird/bin/cache/flutter/5d7eab0b8cc0146649c1c37cd1e1968c97d9e5dd/packages/flutter_tools/bin/xcode_backend.dart:341:68)
2025-11-25T12:58:32.6610220Z              #1      Context.embedFlutterFrameworks (file:///Users/runner/.shorebird/bin/cache/flutter/5d7eab0b8cc0146649c1c37cd1e1968c97d9e5dd/packages/flutter_tools/bin/xcode_backend.dart:317:5)
2025-11-25T12:58:32.6610690Z              #2      Context.run (file:///Users/runner/.shorebird/bin/cache/flutter/5d7eab0b8cc0146649c1c37cd1e1968c97d9e5dd/packages/flutter_tools/bin/xcode_backend.dart:60:9)
2025-11-25T12:58:32.6611120Z              #3      main (file:///Users/runner/.shorebird/bin/cache/flutter/5d7eab0b8cc0146649c1c37cd1e1968c97d9e5dd/packages/flutter_tools/bin/xcode_backend.dart:17:5)
2025-11-25T12:58:32.6611380Z              #4      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:312:33)
2025-11-25T12:58:32.6611820Z              #5      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:193:12)
2025-11-25T12:58:32.6612000Z              Command PhaseScriptExecution failed with a nonzero exit code

attached is the full logs

iOS Release Logs (1).zip

omarammarthefirst avatar Nov 25 '25 13:11 omarammarthefirst

This is the same problem of missing a FLUTTER_BUILD_DIR: https://github.com/shorebirdtech/flutter/blob/5d7eab0b8cc0146649c1c37cd1e1968c97d9e5dd/packages/flutter_tools/bin/xcode_backend.dart#L341

Not really sure why.

eseidel avatar Nov 25 '25 20:11 eseidel

I'd be happy to jump on a call or discuss live over Discord if either could help. https://calendly.com/eseidel

eseidel avatar Nov 25 '25 20:11 eseidel

But it appears that somehow FLUTTER_BUILD_DIR isn't being set. It sounds like flutter build is working but shorebird release is not?

eseidel avatar Nov 25 '25 20:11 eseidel

I recommend looking at the output of: grep -i FLUTTER_ ios/Runner.xcodeproj/project.pbxproj. My guess is that you may have FLUTTER_ environment variables hard-coded in your xcodeproj. All FLUTTER_ variables are supposed to be set by ios/Flutter/Generated.xcconfig (which is edited each time by the flutter tool, rather than within the pbxproj directly.

eseidel avatar Nov 26 '25 07:11 eseidel

This could be the cause, I'm using fvm for general development and it might be an oversight, I'm testing this out now.

edited: for reference

(base) omarammar@Omars-MacBook-Pro-2 waj % grep -i FLUTTER_ ios/Runner.xcodeproj/project.pbxproj
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin";
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build";

omarammarthefirst avatar Nov 26 '25 07:11 omarammarthefirst

Nah, those look fine, thanks fo rchecking.

eseidel avatar Nov 26 '25 07:11 eseidel

Worked with Omar this morning. Decided this was https://github.com/flutter/flutter/issues/138795. He regenerated his projects with flutter create and is working on setting them up again as he needs, but they seem to work after the regeneration. ๐Ÿคž

eseidel avatar Nov 26 '25 17:11 eseidel