Add dependency in capacitor plugin

0

I am developing an Ionic Capacitor plugin on the macOS operating system. When I use the command:

npm init @capacitor/plugin plg-download-manager

to create the plugin, only the Sources and Tests folders are created in the ios folder for the plugin, and the Podfile is not generated. This prevents me from adding libraries like Network to the plugin.

/Users/macvps/prj/plg-download-manager-ios

├── CONTRIBUTING.md

├── Package.resolved

├── Package.swift

├── PlgDownloadManagerIos.podspec

├── README.md

├── PlgDownloadManagerIos.podspec

├── android

│ ├── build.gradle

│ ├── gradle

│ ├── gradle.properties

│ ├── gradlew

│ ├── gradlew.bat

│ ├── proguard-rules.pro

│ ├── settings.gradle

│ └── src

├── dist

│ ├── docs.json

│ ├── esm

│ ├── plugin.cjs.js

│ ├── plugin.cjs.js.map

│ ├── plugin.js

│ └── plugin.js.map

├── example-app

│ ├── README.md

│ ├── capacitor.config.json

│ ├── dist

│ ├── ios

│ ├── node_modules

│ ├── package.json

│ ├── src

│ └── vite.config.ts

├── ios

│ ├── Sources

│ └── Tests

├── node_modules

│ .

│ .

│ .

├── package-lock.json

├── package.json

├── rollup.config.js

├── src

│ ├── definitions.ts

│ ├── index.ts

│ └── web.ts

└── tsconfig.json

node version 22.8.0

capacitor version 6.1.2

ionic version 7.2.0

Please help me.

I tried to create Podfile manually but didn’t work

Add them in the podspec file, the Podfile is only used if you want to build the plugin separate from an app, but the apps will install the dependencies in the podspec, not in the Podfile

Also the plugins now support SPM, so you can also add the dependency in the Package.swift

i want to build the plugin separate from an app and when i add dependency into Package.swift and run swift build give following error

macvps@Catalinas-Mac test-003 % swift build        
Building for debugging...
error: emit-module command failed with exit code 1 (use -v to see invocation)
/Users/macvps/prj/test-003/ios/Sources/TestPlgPlugin/TestPlgPlugin.swift:2:8: error: no such module 'Capacitor'
 1 | import Foundation
 2 | import Capacitor
   |        `- error: no such module 'Capacitor'
 3 | 
 4 | /**
/Users/macvps/prj/test-003/ios/Sources/TestPlgPlugin/TestPlgPlugin.swift:2:8: error: no such module 'Capacitor'
 1 | import Foundation
 2 | import Capacitor
   |        `- error: no such module 'Capacitor'
 3 | 
 4 | /**
/Users/macvps/prj/test-003/ios/Sources/TestPlgPlugin/TestPlgPlugin.swift:2:8: error: no such module 'Capacitor'
 1 | import Foundation
 2 | import Capacitor
   |        `- error: no such module 'Capacitor'
 3 | 
 4 | /**

Don’t know why the swift build command fails to build, but we use xcodebuild command, the plugin should already have a verify:ios npm script that runs xcodebuild internally.