microsoft / plcrashreporter

Reliable, open-source crash reporting for iOS, macOS and tvOS
Other
2.88k stars 537 forks source link

Unable to use PLCrashReporter in simulator when embedded in xcframework #287

Closed Kumail-51214 closed 1 year ago

Kumail-51214 commented 1 year ago

Description

I am creating a xcframework, and inside that xcframework, I am using PLCrashReporter in form of SPM. I am using @_implementationOnly property wrapper to import CrashReporter inside my xcframework. It builds fine. I am making xcframework using following command:

xcodebuild archive \
-scheme MyFramework \
-configuration Release \
-destination 'generic/platform=iOS Simulator' \
-archivePath './build/MyFramework.framework-iphonesimulator.xcarchive' \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
xcodebuild archive \
-scheme MyFramework \
-configuration Release \
-destination 'generic/platform=iOS' \
-archivePath './build/MyFramework.framework-iphoneos.xcarchive' \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
xcodebuild -create-xcframework \
-framework './build/MyFramework.framework-iphonesimulator.xcarchive/Products/Library/Frameworks/MyFramework.framework' \
-framework './build/MyFramework.framework-iphoneos.xcarchive/Products/Library/Frameworks/MyFramework.framework' \
-output './build/MyFramework.xcframework'`

Now when I use that xcframework in my app, it works fine when I build it on physical device. But when I build it for simulator, it gives me following compile-time error:

Fatal runtime error occurred : The target platform is set to iPhoneSimulator, but the project has dynamic framework that are getting stubbed. This is currently not supported.

This issue is not faced when I integrate PLCrashReporter SDK directly in my project and run on simulator.

What can be the possible problem here? Any Suggestions/Solution would be appreciated!

DmitriyKirakosyan commented 1 year ago

Hi @Kumail-51214 , thank you for contacting us!

Have you tried to import any other dependencies of our library with @_implementationOnly? To understand if the issue is specific to PLCR or not. I'm not familiar with this feature (@_implementationOnly) and couldn't find a public doc from apple on supported scenarios. So, I would suggest to open a ticket on the apple developer portal as well.

Also, might be worth checking architectures:

lipo -info ./build/MyFramework.framework-iphonesimulator.xcarchive/Products/Library/Frameworks/MyFramework.framework/MyFramework

Ensure you see x86_64 and/or arm64 for the simulator.

It would be helpful if you could create a minimal project that replicates your scenario. It would also be beneficial to share this with Apple.

Kumail-51214 commented 1 year ago

Hey @DmitriyKirakosyan , thanks for replying back. I have just used @_implementationOnly CrashReporter and initialized SDK using the code provided in documentation.

About@_implementationOnly, I only used it because I was unable to use any third party library in my XCFramework, and as a workaround, it was suggested to use this property wrapper.

For you to better understand my issue, I have created a git project, in which I have included SDK Project, SDK XCFramework & Project in which I am integrating SDK. Below is the link:

https://github.com/Kumail-51214/SDKTesting

Hoping to hear from you soon.! Thanks

DmitriyKirakosyan commented 1 year ago

Thank you so much for the example.

About@_implementationOnly, I only used it because I was unable to use any third party library in my XCFramework, and as a workaround, it was suggested to use this property wrapper.

Could you provide more details on this? Why wouldn't it possible using your library without @_implementationOnly?

Kumail-51214 commented 1 year ago

20230904-102224

20230904-102454

@DmitriyKirakosyan , if i don't use @_implementationOnly while using CrashReporter in my SDK, then when i make SDK using the commands provided above, and then use that SDK in any project i get following error as in the image above. Error occur both on Simulator as well as Physical device.

However, SDK itself builds fine without any errors. Only when that SDK is used in form of .xcframework in any project, the above issue arise.

DmitriyKirakosyan commented 1 year ago

@Kumail-51214, it appears that there may be an issue with the integration of your SDK and PLCrashReporter. In most cases, it should work without the need for @_implementationOnly, unless there are specific build configuration or integration issues.

As a reference, you can examine the AppCenter SDK as an example. It utilizes PLCrashReporter without @_implementationOnly and integrates seamlessly into iOS applications without encountering any problems.

Kumail-51214 commented 1 year ago

@DmitriyKirakosyan , did you tried and run the project/SDK that I've provided? Also, currently my SDK is dynamic Linked (Default). Can that be the issue? Should I change it to Statically Linked Library?

DmitriyKirakosyan commented 1 year ago

@Kumail-51214 , yes, I tried, but it builds and runs on simulator successfully for me. I'm running the IntegratingTestSDK.

Also, currently my SDK is dynamic Linked (Default). Can that be the issue? Should I change it to Statically Linked Library?

Using static or dynamic lib is your choice and there are cons and pros. However, I'm still not sure why it doesn't work for you without using @_implementationOnly. Normally, it should.

DmitriyKirakosyan commented 1 year ago

I'm going to close this issue. Please let me know if you have additional questions.