I have a common dir at the root dir of the plugin that holds code that should be shared by both iOS and MacOS. I changed the source_files
in the .podspec
files of both to point to the common dir: s.source_files = '../common/Classes/**/*'
, but now when I build either of the ios/macos examples, build fails with error that it can't find the plugin import.
/Flutter/GeneratedPluginRegistrant.swift:8:8: error: no such module 'plugin_name'
Is this the right way to share code between iOS and Macos? How do I fix this?
It appears that it wasn't the right way to share code between iOS and MacOS. Instead what I should've done is:
.podspec
files unchanged.ios/Classes
and macos/Classes
(assuming in corresponding directory):ln -s ../../apple/Classes/SwiftSomePlugin.swift SwiftSomePlugin.swift
In my case I had only one file, but if you have more files, you need to create symlink per each file.
The end result should look like this:
├── apple
│ └── Classes
│ └── SwiftSomePlugin.swift
├── ios
│ ├── Assets
│ ├── Classes
│ │ ├── SomePlugin.h
│ │ ├── SomePlugin.m
│ │ └── SwiftSomePlugin.swift -> ../../apple/Classes/SwiftSomePlugin.swift
│ └── some.podspec
├── macos
│ ├── Classes
│ │ └── SwiftSomePlugin.swift -> ../../apple/Classes/SwiftSomePlugin.swift
│ └── some.podspec
Now run the build and it should succeed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.