airbnb / lottie-ios

An iOS library to natively render After Effects vector animations
http://airbnb.io/lottie/
Apache License 2.0
25.76k stars 3.75k forks source link

lottie-spm crashing on device when used inside a framework target #2201

Closed apps4everyone closed 1 year ago

apps4everyone commented 1 year ago

Hey,

wanted to switch to lottie-spm but the app is crashing on device when used inside a framework target (not directly in the main app target.

My main app

On device there is the crash with this error: (no such file)Library not loaded: @rpath/Lottie.framework/Lottie

Only change: https://github.com/airbnb/lottie-ios.git -> https://github.com/airbnb/lottie-spm.git

calda commented 1 year ago

Can you please share a sample project that demonstrates this issue?

calda commented 1 year ago

Also, make sure you're embedding "Lottie.framework" in your app binary in the Xcode "Embedded Libraries" panel

apps4everyone commented 1 year ago

Hey, hopefully this project is ok, please change team and bundle identifiers so you can run on your device.

LottieTest.zip

PS: thx for the quick reply

calda commented 1 year ago

Thanks for the sample project. It builds and runs successfully after I add the Lottie library under "Frameworks, Libraries, and Embedded Content":

Before (crashes)

Screenshot 2023-09-27 at 10 39 38 AM

After (no crash)

Screenshot 2023-09-27 at 10 39 47 AM
apps4everyone commented 1 year ago

Hey, sorry for the late reply but this is only a bad workaround because this would copy the binary twice to the app. And also this is not needed with the non XCFramework version in https://github.com/airbnb/lottie-ios/ I guess it is a SPM related bug.

apps4everyone commented 1 year ago

The transitive dependency should work without adding the Lottie library under "Frameworks, Libraries, and Embedded Content" again. It is already in LottieTest -> LottieTestFrameworkKit -> LottieTestFramework Or why it is working with https://github.com/airbnb/lottie-ios/ ?

apps4everyone commented 1 year ago

here is the example with https://github.com/airbnb/lottie-ios/ LottieTestNONSPM.zip

apps4everyone commented 1 year ago

I guess this is not 100% working when used in sub dependencies https://github.com/airbnb/lottie-spm/blob/main/Package.swift#L20

// Without at least one regular (non-binary) target, this package doesn't show up // in Xcode under "Frameworks, Libraries, and Embedded Content". That prevents // Lottie from being embedded in the app product, causing the app to crash when // ran on a physical device. As a workaround, we can include a stub target // with at least one source file. .target(name: "_LottieStub"),

calda commented 1 year ago

If embedding the library in that way doesn't work for your use case, you could continue using the lottie-ios repo.