chipweinberger / flutter_blue_plus

Flutter plugin for connecting and communicationg with Bluetooth Low Energy devices, on Android, iOS, macOS
Other
781 stars 471 forks source link

[Help]: dyld[2179]: Symbol not found: _OBJC_CLASS_$_FlutterError #581

Closed kbessemer closed 1 year ago

kbessemer commented 1 year ago

FlutterBluePlus Version

1.4.0

Flutter Version

3.13.4

What OS?

iOS

OS Version

iOS 15.7.9 & iOS 17

Bluetooth Module

STM32

What happened?

The flutter app will not start on iOS, it crashes immediately.

Logs

dyld[2179]: Symbol not found: _OBJC_CLASS_$_FlutterError
  Referenced from: <D26B8D55-5052-3B29-A2D1-64F3A74A6628> /private/var/containers/Bundle/Application/54180268-0E54-41B4-A5ED-E03F662FAE86/Runner.app/Runner
  Expected in:     <6DD9F429-0BD2-3581-B55F-23B9A86E1CC2> /private/var/containers/Bundle/Application/54180268-0E54-41B4-A5ED-E03F662FAE86/Runner.app/Frameworks/flutter_blue_plus.framework/flutter_blue_plus
kbessemer commented 1 year ago

I resolved this bug by upgrading my Flutter Blue Plus plugin to 1.15.8

Yongle-Fu commented 1 year ago

https://stackoverflow.com/questions/77144171/dyld2179-symbol-not-found-objc-class-fluttererror/77149456#77149456

Yongle-Fu commented 1 year ago

same issue, anything reason ?

kbessemer commented 1 year ago

same issue, anything reason ?

upgrade your plugin to 1.15.8

Yongle-Fu commented 1 year ago

Thank you for your reply. I understand that checked the change log between versions 1.40 and 1.15.8, but couldn't find any mention of this issue. Could you please tell me some specific reason?

Yongle-Fu commented 1 year ago

found reason, this commit fixed the issue: [Protobuf] remove protobuf from iOS and MacOS

I use flutter_blue in my code (not plus), so these are my options to fix the error:

  1. migrate the flutter_blue_plus
  2. refactor to swift protobuf also worked.
  3. remove permission_handler dependency
vinicz commented 1 year ago

found reason, this commit fixed the issue: [Protobuf] remove protobuf from iOS and MacOS

I use flutter_blue in my code (not plus), so these are my options to fix the error:

  1. migrate the flutter_blue_plus
  2. refactor to swift protobuf also worked.
  3. remove permission_handler dependency

@Yongle-Fu the issue is not that bad, found a hint here https://developer.apple.com/forums/thread/735610, the main cause is that the old flutter_blue code still catches and throws FlutterErrors, this was changed here as well. After we got rid of that in our fork everything worked again. (But would still recommend migrating to this plugin at some point)

chipweinberger commented 1 year ago

Contents of: https://developer.apple.com/forums/thread/735610


I was migrating from Xcode 14 -> 15, and noticed that my code was failing with dyld[46534]: Symbol not found: _OBJC_CLASS_$_NSError

I was able to debug the problem to some old objective c code, as documented in this thread: https://github.com/RonRadtke/react-native-blob-util/issues/273

The error seems to stem from this particular try catch block

@try {
    // Some code
}
@catch(NSError *er) {
    // handle error
}

When I convert the code to catch an NSException instead, the runtime error goes away. Understandably, according to the apple docs, it should be throwing an NSException in the first place, but the documents do say

Important: Although you can throw and catch objects other than NSException objects, the Cocoa frameworks themselves might only catch NSException objects for some conditions. So if you throw other types of objects, the Cocoa handlers for that exception might not run, with undefined results. (Conversely, non-NSException objects that you throw could be caught by some Cocoa handlers.) For these reasons, it is recommended that you throw NSException objects only, while being prepared to catch exception objects of all types.

So it seems like this should not have produced a runtime error. I wanted to flag this in case the underlying code behind the @try @catch changed unintentionally.

Yongle-Fu commented 1 year ago

Thank you for your help, i had update the objective c code to swift code and remove the try catch block indeed.

chipweinberger commented 11 months ago

so to summarize, a simple fix is to fork the old FBP and remove any catching or throwing of FlutterError. this was invalid code. It should be NSException. see master branch for details. i.e.

    @catch (NSException *e)
    {
        NSString *stackTrace = [[e callStackSymbols] componentsJoinedByString:@"\n"];
        NSDictionary *details = @{@"stackTrace": stackTrace};
        result([FlutterError errorWithCode:@"iosException" message:[e reason] details:details]);
    }