Search code examples
iosswiftcocoapodscapacitorcapacitor-plugin

Capacitor plugin using sdk.xcframework, how to avoid having the xcframework 2 times in my plugin?


I am developing a capacitor plugin for my ionic app and it's using a 3d party sdk.

In order to use it in my ios Plugin.swift I copy the .xframework in my plugin's ios folder, add pod ' ', :path => '' in the Plugin/ios .podfile and run pod install. That makes the sdk available for my plugin.

When I build and open my ios project that includes the plugin in xcode I get an error at my sdk import. The way to get past this error is adding the .xcframework in the root of my capacitor plugin and add it as s.vendored_frameworks = " " in my plugins .podspec.

Is there a way to avoid adding the .xcframework two times in my plugin(root & ios folder)?

I've tried a relative path in the s.vendored_frameworks ="./ios/Frameworks/my_framework.xcframework" that doesn't seem to work.


Solution

  • After doing a clean install relative path worked! steps I used to solve this:

    • in my myPlugin I put my framework in ios/Frameworks/myFramework.xcframework
    • in ios.podfile add the framework pod: pod '', :path => './Frameworks/myFramework.podspec
    • in the plugins root podspec: s.vendored_frameworks = 'ios/Frameworks/myframework.xcframework

    pod deintergrate & pod install in myPlugin/ios npm install & npx cap sync in my project

    now both my plugin & the project can see the sdk import