tinyjin / lottie-thorvg

Fast and compact Lottie for Flutter using ThorVG as a renderer. (beta)
https://pub.dev/packages/lottie_thorvg
MIT License
8 stars 0 forks source link

iOS Simulator linking issue (Apple Silicon) #4

Open tinyjin opened 6 months ago

tinyjin commented 6 months ago

Installation bug from building with iOS Simulator hosted by M1 (SoC) Probably, dylib for ios-sim on arm64 is missing.

Launching lib/main.dart on iPhone 15 Pro in debug mode...
Running pod install...                                           1,252ms
Running Xcode build...
 └─Compiling, linking and signing...                        10.4s
Xcode build done.                                           35.3s
Failed to build iOS app
Error (Xcode): Building for 'iOS-simulator', but linking in dylib
(../ios/Frameworks/libthorvg.dylib) built for 'iOS'

Error (Xcode): Linker command failed with exit code 1 (use -v to see invocation)

Could not build the application for the simulator.
Error launching application on iPhone 15 Pro.
tinyjin commented 6 months ago

Previously, iOS binary is built with lipo (Fat Binary). In the Fat Binary, simulator binary for Apple Silicon cannot be merged in single binary due to the same architecture with iPhone OS.

The ideal approach is to build a xcframework, which is more optimal and suitable as a universal binary.

Frameworks/libthorvg.xcframework

# lottie_thorvg.podspec
s.vendored_frameworks = 'Frameworks/libthorvg.xcframework'

We can build them via script:

# Universal sim binary
lipo path/to/ios-simulator/aarch64/libthorvg.dylib \
path/to/ios-simulator/x86_64/libthorvg.dylib \
-output libthorvg.dylib -create

# Build xcframework
xcodebuild -create-xcframework \
-library path/to/ios/libthorvg.dylib \
-library path/to/ios-simulator/libthorvg.dylib \
-output libthorvg.xcframework