Skip to content

Also link dynamically when using Swift Package Manager#239

Open
FrankenApps wants to merge 3 commits into
khoren93:mainfrom
FrankenApps:ios-archive-strip-fix
Open

Also link dynamically when using Swift Package Manager#239
FrankenApps wants to merge 3 commits into
khoren93:mainfrom
FrankenApps:ios-archive-strip-fix

Conversation

@FrankenApps

@FrankenApps FrankenApps commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

This is a critical fix for iOS and macOS after the migration to Swift Package Manager.

Background

Albeit flutter run and flutter run --release work just fine for iOS at the moment, in an app built for distribution with flutter build ipa, the barcode detection does not work at all.

The reason for this is that during archiving XCode strips exported symbols by default.

Fix

I fixed the regression by using dynamic linking as has been done with CocoaPods before.

Validation

Because I found it rather difficult to pin-point / validate the issue initially, I thought I'd provide a small overview for how to do it with the sample app, just in case you want to verify the change.

  1. Optionally prepare native source if needed with git submodule update --init --recursive && ./scripts/update_ios_macos_src.sh
  2. cd example
  3. flutter pub get
  4. cd ios
  5. Run archive build (which includes stripping)
xcodebuild \
  -workspace Runner.xcworkspace \
  -scheme Runner \
  -configuration Release \
  -sdk iphoneos \
  -archivePath /tmp/Runner.xcarchive \
  archive \
  CODE_SIGNING_ALLOWED=NO CODE_SIGNING_REQUIRED=NO
  1. Check if symbols are still there (with the fix they are still present, without it you have to check a bit different; See below):
xcrun dyld_info -exports "/tmp/Runner.xcarchive/Products/Applications/Runner.app/Frameworks/flutter-zxing.framework/flutter-zxing" \
  | grep -E '_readBarcode$|_readBarcodes$|_encodeBarcode$|_setLogEnabled$|_version$'

or

nm -gU "/tmp/Runner.xcarchive/Products/Applications/Runner.app/Frameworks/flutter-zxing.framework/flutter-zxing" \
  | grep -E '_readBarcode$|_readBarcodes$|_encodeBarcode$|_setLogEnabled$|_version$'

Note that the whole framework is gone with the current main branch (you can for example verify this with otool -L "/tmp/Runner.xcarchive/Products/Applications/Runner.app/Runner" | grep zxing which does not find the framework on main, but does with the fix), but you can still somewhat verify the issue, by checking if the symbols are present in the statically linked app:

nm "/tmp/Runner.xcarchive/Products/Applications/Runner.app/Runner" | grep -E '_readBarcode|_readBarcodes|_encodeBarcode'

as you will see the symbols are not present which means they were stripped out by XCode.

Alternative

Alternatively we could instruct users in the README to enable the Non-Global Symbols Strip Style in their iOS and macOS XCode projects and keep linking statically, but I think providing a central fix here, that also aligns with the previous behavior when using CocoaPods is the preferred option.

Notes on the PR

  1. I also included the .build/ directory of the native iOS and macOS projects in the .gitignore which is the standard practice
  2. I prepared the library for a new release by bumping the version and updating the Changelog, because I think this fix is critical enough for a new release, but if you disagree or want to do this yourself I can remove that commit?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant