I am building a Flutter plugin [MyPlugin] which depends on proprietary native SDKs (one for iOS one for Android). I then need to add this plugin as a dependency to a Flutter app I am also developing [myApp]. This app has, in iOS, a custom keyboard extension. Both the keyboard extension and the app are dependent on functionality within the MyPlugin, hence I need to add this dependency to both targets. MyPlugin can be integrated into the Flutter app (and specifically in iOS) with cocoapods.
In the podspec of the plugin I add the dependency on the native SDK [MyNativeSDK].
file my_plugin/ios/my_plugin.podspec
Pod::Spec.new do |s|
s.name = 'my_plugin'
s.version = '0.0.1'
s.summary = 'A Flutter plugin'
s.description = <<-DESC
A new Flutter plugin
DESC
s.homepage = 'https://myplugin.com'
s.license = { :file => '../LICENSE' }
s.author = { 'Me' => '[email protected]' }
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.dependency 'Flutter'
s.dependency 'MyNativeSDK', '0.7.2'
s.platform = :ios, '15.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'
end
Then I try to add to both my targets (in the example within the plugin) the dependency on the plugin (without it the code does not even build).
file my_plugin/example/ios/Podfile
target 'Runner' do
use_frameworks!
use_modular_headers!
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
target 'MyKeyboardExtension' do
inherit! :search_paths
end
end
Unfortunately, when running the app I get a couple of problems:
- A duplication warning that Realm is linked twice and it is unclear which one of the two will be used (which I believe to be the core of the issue here)
objc[4797]: Class _TtC10RealmSwiftP33_DFF53EDC9789EA51BB3D260332C05DF321ProjectionSchemaCache is implemented in both
/private/var/containers/Bundle/Application/429179EE-8537-4928-9751-F9329EA58C42/Runner.app/Frameworks/RealmSwift.framework/RealmSwift (0x104780768) and /private/var/containers/Bundle/Application/429179EE-8537-4928-9751-F9329EA58C42/Runner.app/Frameworks/MyNativeSDK.framework/MyNativeSDK (0x105894240). One of the two will be used. Which one is undefined.
- the second is that the app does build and run, but whenever I try to call functionality of the Plugin for within the app (or from within the keyboard extension) the app crashes with a BAD EXC message.
Thread 31: EXC_BAD_ACCESS (code=1, address=0xfffffffffffffff8)
I believe the issue is due to Realm being linked twice, but it is unclear to me if this “double linkage” is due to having the need to add the MyNativePlugin dependency in both targets (Runner and Keyboard Extension) or because Realm is already linked twice in MyNativeSDK.
For info, the same MyNativeSDK works fine when integrated in a native iOS app that also has a keyboard extension: does not show any warning nor throws any error when used.
Enea Ceolini is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.