A typical Capacitor plugin has two places to configure dependencies for iOS. The `Podfile` and the `.podspec` file. These two files serve two distinct purposes. The first is used for configuring dependencies for the plugin development environment. The second is for configuring dependencies used in the consuming project. These can be compared to the devDependencies and dependencies respectively that would be found in a package.json file of a web application project.
Typical plugin structure:
|- android/
|- ios/
|- Podfile // devDependencies
|- src/
|- PluginName.podspec // dependencies
Example Podfile
platform :ios, '11.0'
def capacitor_pods
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
pod 'Capacitor', :path => '../node_modules/@capacitor/ios'
pod 'CapacitorCordova', :path => '../node_modules/@capacitor/ios'
end
target 'Plugin' do
capacitor_pods
pod 'MyCustomPodDepName', 'pod.version.number'
end
target 'PluginTests' do
capacitor_pods
end
Example PluginName.podspec
Pod::Spec.new do |s|
s.name = 'PluginName'
s.version = 'plugin.version.number'
s.summary = 'A summary about my cool plugin'
s.license = 'MIT'
s.homepage = 'https://github.com/my/pluginrepo
s.author = 'Me'
s.source = { :git => 'https://github.com/my/pluginrepo.git', :tag => s.version.to_s }
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
s.ios.deployment_target = '11.0'
s.dependency 'Capacitor'
s.dependency 'MyCustomPodDepName', 'pod.version.number'
end
Multiple pod dependencies can be added this way by adding the required pods to the `target Plugin` section of the Podfile and additional `s.dependency` lines to the .podspec file
Comments
1 comment
Hi, James,
1) I'm using Google MLKit Translate in my custom capacitor plugin by my podfile(devDependencies):
target 'Plugin' do
capacitor_pods
pod 'GoogleMLKit/Translate', '3.2.0'
end
2) And I also added it to the podspec(dependencies):
s.dependency 'GoogleMLKit/Translate', '3.2.0'
3) I still got error message from my target APP:
No such module 'MLKitTranslate'
Is there anything need to do?
Thank you.
Please sign in to leave a comment.