Capacitor plugin with 3rd party iOS framework

I’m attempting to build a capacitor plugin which requires a 3rd party framework for iOS. So my setup looks like this:

my-ionic-app-for-testing ← my-capacitor-plugin ← 3rd-party-framework

Presently, I can get my-capacitor-plugin to compile with the 3rd-party-framework, but when I include my-capacitor-plugin into my-ionic-app-for-testing, I get compile errors “3rd-party-framework” not found.

Additional Details: I’m guessing I made a mistake in how I attempted to create this dependency chain.

my-capacitor-plugin ← 3rd-party-framework

The 3rd-party-framework recommends installing it using the Carthage build tool. I create my-capacitor-plugin/Cartfile, include the dependency I need, and run $ carthage update . This creates the my-capacitor-plugin/Carthage/Build/iOS/3rd-party.framework directory. In the Xcode ‘general’ tab, I drop this folder into ‘Frameworks and Libraries’ for Pods with targets “Capacitor” and “Pods-Plugin”, and for Plugin with target “Plugin”. At this point I import the 3rd-party-framework into Plugin.swift (import ThirdParty), the project then builds in Xcode. (It is perhaps worth noting that the 3rd-party-framework itself is written in ObjectiveC, though xcode seems to know how to translate this into a swift import on its own.)

my-ionic-app-for-testing ← my-capacitor-plugin

In my-ionic-app-for-testing/package.json I have…

“dependencies”: {

“my-capacitor-plugin”: “file:…/my-capacitor-plugin”,

},

where the filepath points to the root of the my-capacitor-plugin project. I build the project with:

$ npm i
$ ionic build
$ npx cap sync

I try building with xcode, pointing to my-ionic-app-for-testing/ios/App/App.xcworkspace, where I get the above “3rd-party-framework” not found errors.

In looking around, this post swift - How to embed third party framework on ionic capacitor custom plugin? - Stack Overflow suggests I need to additionally edit my-capacitor-plugin/MyCapacitorPlugin.podspec. Other posts have suggested I need to add additional run scripts or copy file scripts within the my-capacitor-plugin xcode project. I haven’t gotten any permutation of these ideas to work.

Any help would be greatly appreciated

You have to add the framework in the podspec as that answer suggest

1 Like

Hey,bro. How you solved your problem? i have the same problem now?

The third party obejctive-c framework don’t have modulemap file, and allways show the not found error. please help me!

I added the framework to to the podspec of my CustomPlugin like suggested. Everything was working fine till I started using xCode 14. Now I’m getting the following error when I try to archive my app.

framework module 3rdPartyFramework {
  umbrella header "3rdPartyFramework.h"

  export *
  module * { export * }
}

module 3rdPartyFramework.Swift {
    header "3rdPartyFramework-Swift.h"
    requires objc
}

Line 2 error: Umbrella for module 'CustomPlugin' already covers this directory
Line 5 error: Inferred submodules require a module with an umbrella

Do you know what I need to change in my CustomPlugin podspec to fix these errors?