1 year ago
#233433
MaxiStarling
Flutter plugin - ios vendored library linking errors
I'm having a lot of issues trying to implement a native ios library into a flutter plugin, this is the plugin podspec:
Pod::Spec.new do |s|
s.name = 'flpl'
s.version = '0.0.1'
s.summary = 'A new flutter plugin project.'
s.homepage = 'http://example.com'
s.license = { :text => 'License Text' }
s.author = { 'Example' => 'example@example.com' }
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h'
s.dependency 'Flutter'
s.platform = :ios, '12.0'
s.subspec 'vLib' do |ss|
ss.preserve_paths = 'libVendored.a'
ss.ios.vendored_libraries = 'libVendored.a'
ss.xcconfig = { 'OTHER_LDFLAGS': "-ObjC", 'ENABLE_BITCODE' => 'NO' }
end
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
end
Note: iOS 13 was chosen because it gave the least amount of compile-time errors, not for a specific reason
This is the generalized file structure:
android
example
↳ ios
↳ Podfile
lib
ios
↳ Assetts
↳ Classes
↳ vLib
↳ someHeaderFile.h
↳ flplPlugin.h
↳ flplPlugin.m
↳ libVendored.a
↳ flpl.podspec
flplPlugin.h
: no difference from what flutter creates.
flplPlugin.m
:
#import "FlplPlugin.h"
#import "someHeaderFile.h"
@implementation FlplPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar
{
FlutterMethodChannel* channel = [FlutterMethodChannel methodChannelWithName:@"flpl" binaryMessenger:[registrar messenger]];
FlplPlugin* instance = [[FlplPlugin alloc] init];
[registrar addMethodCallDelegate:instance channel:channel];
}
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result
{
if ([@"ping" isEqualToString:call.method])
{
result(@"pong");
}
else if ([@"auth" isEqualToString:call.method])
{
--=*( call to someHeaderFile class functions )*=--
}
}
@end
When I try to build the plugin's example app (flutter clean; flutter build ios
inside the example folder) xcode errors with the following:
ld: warning: object file (/path_2_plugin/example/build/ios/Release-iphoneos/flpl/libVendored.a(FlplPlugin.o)) was built for newer iOS version (12.0) than being linked (9.0)
ld: warning: object file (/path_2_plugin/example/build/ios/Release-iphoneos/flpl/libVendored.a(flpl-dummy.o)) was built for newer iOS version (12.0) than being linked (9.0)
Undefined symbols for architecture arm64:
"_OBJC_CLASS_$_SomeHeaderFileClass", referenced from:
objc-class-ref in libVendored.a(FlplPlugin.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ld: warning: ignoring file /path_2_plugin/example/build/ios/Release-iphoneos/flpl/libVendored.a, building for iOS-armv7 but attempting to link with file built for iOS-arm64
Undefined symbols for architecture armv7:
"_OBJC_CLASS_$_FlplPlugin", referenced from:
objc-class-ref in GeneratedPluginRegistrant.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error (Xcode): Undefined symbol: _OBJC_CLASS_$_SomeHeaderFileClass
Error (Xcode): Undefined symbol: _OBJC_CLASS_$_FlplPlugin
Encountered error while building for device.
Looking into the library though, I found it:
nm -g /path_2_plugin/.../flpl/libVendored.a | grep '_OBJC_CLASS_$_SomeHeaderFileClass'
outputs: U _OBJC_CLASS_$_SomeHeaderFileClass
Flutter doctor:
[✓] Flutter (Channel stable, 2.10.2, on macOS 12.1 21C52 darwin-arm, locale it)
[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
Also tried on a non M1 Mac but had the same errors. Non-M1 Flutter doctor:
[✓] Flutter (Channel stable, 2.10.2, on macOS 11.4 20F71 darwin-x64, locale it-IT)
[!] Xcode - develop for iOS and macOS (Xcode 12.5.1)
(i currently cannot upgrade xcode on the non m1 mac)
ios
objective-c
flutter
flutter-plugin
podspec
0 Answers
Your Answer