realm-swift icon indicating copy to clipboard operation
realm-swift copied to clipboard

XCFramework is crashing with latest RealmSwift version on Real.configuration

Open amirpervaizQI opened this issue 1 year ago • 12 comments

How frequently does the bug occur?

Always

Description

Hi, I am making XCFrameworkk with the -ObjC linkers as mentioned in another thread. Realmswift v10.38.0 is a dependency in the podspecs file.

xcodebuild -create-xcframework \
    -framework "./build/ios.xcarchive/Products/Library/Frameworks/sdk.framework" \
    -framework "./build/ios_sim.xcarchive/Products/Library/Frameworks/sdk.framework" \
    -output "./build/sdk.xcframework"
    -ldflags "-Wl,-ObjC"

but it is crashing on init Realm at configuration. Please see the screenshot below:

Screenshot 2023-04-25 at 10 41 18 AM

I am using RealSwift 10.38.0 and have tried a few older versions but getting the same error. It used to work with 10.19.0.

It also working when I use the code instead of XCFramework. Could you please check this issue?

Thanks.

Stacktrace & log output

No response

Can you reproduce the bug?

Always

Reproduction Steps

No response

Version

10.38.0

What Atlas Services are you using?

Local Database only

Are you using encryption?

Yes

Platform OS and version(s)

iOS 16.3

Build environment

Xcode version: Version 14.2 (14C18) Dependency manager and version: Cocoapods 1.12.1

amirpervaizQI avatar Apr 25 '23 02:04 amirpervaizQI

Hi @amirpervaizQI, can you try producing the XCFrameworks with our build script instead?

Clone the realm-swift repo and then run ./build.sh xcframework ios

leemaguire avatar Apr 25 '23 09:04 leemaguire

Hi @leemaguire thank you for your reply. Sorry If I didnt explain my question clearly. I am building a custom XCFramework and that is using RealmSwift as a dependency. When I build my XCFramework and distribute it via cocoapods by using Realm dependency as s.dependency 'RealmSwift', '10.38.0' in my podspecs file. Then, it is throwing the above crash in an app.

Whereas when I use my custom Framework via code with RealSwift in the app, I dont observer any crash. The issue is happening with the latest swift versions with the XCFramework. Though it seems to be working with an older version 10.19.0.

Should I make Realm/RealmSwift XCFramework with the script and use it in my Framework?

amirpervaizQI avatar Apr 26 '23 01:04 amirpervaizQI

Hi @amirpervaizQI I was able to reproduce your issue and I was able to find a workaround One solution will be to set to BUILD_LIBRARY_FOR_DISTRIBUTION=NO when you archive your frameworks and add -allow-internal-distribution when you create your xcframework.There may be some Apple's issues in swift-evolution which may be causing some issues which may be causing this crashes, this will allow you to append the RealmSwift SDK using cocoapods. If you do want to set BUILD_LIBRARY_FOR_DISTRIBUTION to YES Yo can generate Realm and RealmSwift xcframework ./build.sh xcframework ios like it was suggested above and link it to your framework, generate your xcframework and then add the three xcframeworks to your app (Your framework, RealmSwift and Realm). I tested both approaches and they seem to be working, let me know if this is helpful.

dianaafanador3 avatar May 24 '23 14:05 dianaafanador3

Thanks @dianaafanador3 , I got these errors when I try to compile my framework with Realm.xcframework and RealmSwift.xcframework manually created by the above command you mentioned.

Screenshot 2023-05-26 at 3 37 35 PM

Using Xcode 14.3 and used the XCFramework in swift-14.3 folder.

amirpervaizQI avatar May 26 '23 07:05 amirpervaizQI

@amirpervaizQI is this missing symbol only for the current architecture? Can you please share which Xcode, RealmSwift and target device version are you using?

dianaafanador3 avatar May 26 '23 07:05 dianaafanador3

-Xcode 14.3 -pod: 1.12.0 -For RealmSwift, I pulled the latest code from the master branch. I believe the release is 10.39.1. I am compiling Framework for arAny iOS Device (arm64)

amirpervaizQI avatar May 26 '23 07:05 amirpervaizQI

@amirpervaizQI how are you importing the xcframework into your own framework?. I'm attaching a simple example project, where it's building correctly. SupportXCFramework.zip

dianaafanador3 avatar May 31 '23 11:05 dianaafanador3

Hi @dianaafanador3 thank you so much for sharing the sample app. I checked it and it worked in the sample app. However, in my case, I cant embed RealmSwift inside of the XCFramework. The above error occurs while integrating from pod. I tried the latest pod but still the same. I think its linked with BUILD_LIBRARY_FOR_DISTRIBUTION what you mentioned above.

amirpervaizQI avatar Jun 27 '23 04:06 amirpervaizQI

Hi @dianaafanador3 could you pls check what got changed from 10.21.0 onwards that broke the RealmSwift in an XCFramework? I found this ticket https://github.com/realm/realm-swift/issues/7989 it explains the same issue. I would appreciate your help looking into it. I just tried the latest version 10.44.0 but still it breaks when used as a dependency in the XCFramework.

thanks.

amirpervaizQI avatar Nov 29 '23 13:11 amirpervaizQI

Still looking for a fix. Please update.

amirpervaizQI avatar Jan 24 '24 04:01 amirpervaizQI

Check out this workaround https://github.com/realm/realm-swift/issues/7989#issuecomment-1953963196

themoonlitknight avatar Feb 20 '24 11:02 themoonlitknight

Hi @dianaafanador3 I recently tested one of my old project - which was originally created using Xcode 11 - on Xcode 15.3. Surprisingly, I didnt encounter any crashes while running the XCFramework with RealmSwift as a dependency. I am wondering this could be RealmSwift compatibility issue or Xcode linkers? Any insights you might have on this matter would be greatly appreciated. Thank you.

amirpervaizQI avatar Apr 17 '24 16:04 amirpervaizQI