I got mine working by adding the following lines to the xxx.podspec
:
s.preserve_paths = 'xxxxxx.xcframework/**/*'
s.xcconfig = { 'OTHER_LDFLAGS' => '-framework xxxxxx' }
s.vendored_frameworks = 'xxxxxx.xcframework'
Notice the /**/*
at the end of s.preserve_paths
Here is the full xxx.podspec
file:
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html.
# Run `pod lib lint xxx.podspec` to validate before publishing.
#
Pod::Spec.new do |s|
s.name = 'xxx'
s.version = '1.0.0'
s.summary = 'xxx'
s.description = <<-DESC
xxx is a flutter plugin
DESC
s.homepage = 'https://example.com'
s.license = { :file => '../LICENSE', :type => 'BSD' }
s.author = { 'xxx' => '[email protected]' }
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.dependency 'Flutter'
s.platform = :ios, '10.0'
# Flutter.framework does not contain a i386 slice.
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
s.swift_version = '5.0'
s.preserve_paths = 'xxxxxx.xcframework/**/*'
s.xcconfig = { 'OTHER_LDFLAGS' => '-framework xxxxxx' }
s.vendored_frameworks = 'xxxxxx.xcframework'
# Inorder to add multiple frameworks
s.preserve_paths = ['xxxxxxx.xcframework/**/*', 'yyyyyyy.xcframework/**/*']
s.xcconfig = { 'OTHER_LDFLAGS' => ['-framework xxxxxxx', '-framework yyyyyyy'] }
s.vendored_frameworks = ['xxxxxxx.xcframework', 'yyyyyyy.xcframework']
end
Make sure to copy the xxxxxx.xcframework
directory to .../xxx/ios/xxxxxx.xcframework
(where your plugin xxx.podspec
is located)
Add xxxxxx.xcframework
to Pods
scheme to be able to import it
The Frameworks
directory should be below the Pods
scheme when running the flutter command to create a plugin ie.
flutter create --org com.xxx --template=plugin --platforms=android,ios -a java -i swift xxx
Source: Developing packages & plugins
(If not, add it)
- Navigate to
Pods
scheme and right-click on Frameworks
- Click
Add Files to "Pods"...
- Navigate to the root of the
ios
directory where the xxxxxx.xcframework
is located
- Uncheck
Copy items if needed
- Select
Create folder references
- Check
Pods-Runner
- Check your plugin ie.
xxx
- Click
Add
Embed xxxxxx.xcframework
into your project
(this should allow you to run/publish to real devices)
- Click on the
Pods
scheme
- In
TARGETS
select Pods-Runner
- Click on the
General
tab
- Ensure the
xxxxx.xcframework
is present underneath Frameworks and Libraries
(if not, add it by clicking on the +)
- Change
Embed
to Embed & Sign
- Click on your plugin ie.
xxx
- Ensure the
xxxxx.xcframework
is present underneath Frameworks and Libraries
- Change
Embed
to Embed & Sign
- Again, for both targets below
Pods
scheme, the next steps should already be fine, but just check it
- Click
Build Phases
- Click
Link Binary With Libraries
- Ensure
xxxxx.xcframework
is present, if not add it by clicking the + and that the Status
is set to Required
Now you should be able to import the framework and reference it in your code and should also publish perfectly fine.
Hope this helps, and good luck. I hope this doesn't change again soon
fingers crossed
.xcframework
? Also, you don't need all 3 steps you added (cocoapods, SPM and xcframework). Just drag.xcframework
into your project. – Nous.xcframework
. Also, when a user adds your plugin to their project, your plugin gets added via cocoapods, not SPM. When you block out names, you make things harder to see 😂. SPM is not applicable for you, IMHO. – Nousmy alternative was to add this dependency in other project with SPM and manually copied the .xcframework to my plugin folder
It's really not clear why you're using SPM if you're going to drag the XCF into the plugin folder. Both are bad ideas though, for Flutter plugins. You should configure XCF in Cocoapods usingvendored_frameworks
. It's not a well documented feature though: this issue has an example project. I've never used it – NousPackage.resolved
in the Xcodeproj. It only changes the dependencies on the Podfile/ output ofpod install
. – Nous