Skip to content

Plugin registration crash if registrar is null #149214

Open

Description

@lukehutch

Steps to reproduce

When launching a debug build of a Flutter app from the home screen of iOS, the app will crash when trying to register plugins:

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000000
Exception Codes: 0x0000000000000001, 0x0000000000000000
VM Region Info: 0 is not in any region.  Bytes before following region: 4378574848
      REGION TYPE                 START - END      [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      __TEXT                   104fbc000-105c5c000 [ 12.6M] r-x/r-x SM=COW  /var/containers/Bundle/Application/7B913006-58CD-46F2-8AA4-1CDC1EE0E0C1/Runner.app/Runner
Termination Reason: SIGNAL 11 Segmentation fault: 11
Terminating Process: exc handler [8436]

Triggered by Thread:  0

Thread 0 name:   Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libswiftCore.dylib            	       0x18b58369c swift_getObjectType + 40
1   connectivity_plus             	       0x107f32210 static SwiftConnectivityPlusPlugin.register(with:) + 64
2   connectivity_plus             	       0x107f325a8 @objc static SwiftConnectivityPlusPlugin.register(with:) + 56
3   connectivity_plus             	       0x107f30048 +[ConnectivityPlusPlugin registerWithRegistrar:] + 72
4   Runner                        	       0x104fc4074 +[GeneratedPluginRegistrant registerWithRegistry:] + 116
5   Runner                        	       0x104fc4a04 AppDelegate.application(_:didFinishLaunchingWithOptions:) + 100
6   Runner                        	       0x104fc4e8c @objc AppDelegate.application(_:didFinishLaunchingWithOptions:) + 196

This is a known problem:

#67624
#60657

In particular this is helpful:

#67624 (comment)

This was supposed to be fixed by displaying an error message to the user rather than crashing, in Flutter 1.22:

flutter-team-archive/engine#20980

However, on Flutter 3.22, this dialog does not show for some reason.

Why can the underlying crash not be fixed, rather than displaying the error message?

Why is the error message not showing on latest Flutter?

Expected results

The app should not crash -- or at the very least, the error message should be shown.

Actual results

The app crashes 100% of the time on launch.

Code sample

N/A

Screenshots or Video

N/A

Logs

See full log at fluttercommunity/plus_plugins#2912 (comment)

Flutter Doctor output

Doctor output
% flutter doctor -v
[✓] Flutter (Channel beta, 3.22.0-0.3.pre, on macOS 14.5 23F79 darwin-x64, locale en-US)
    • Flutter version 3.22.0-0.3.pre on channel beta at /Users/luke/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 87b652410d (5 weeks ago), 2024-04-23 21:41:18 -0500
    • Engine revision b4bfd45986
    • Dart version 3.4.0 (build 3.4.0-282.3.beta)
    • DevTools version 2.34.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/luke/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15E204a
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)

[✓] VS Code (version 1.89.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.89.20240501

[✓] Connected device (3 available)
    • iPhone SE (2nd generation) (mobile) • 00008030-000C38343C23402E • ios            • iOS 17.4.1 21E236
    • macOS (desktop)                     • macos                     • darwin-x64     • macOS 14.5 23F79 darwin-x64
    • Chrome (web)                        • chrome                    • web-javascript • Google Chrome 125.0.6422.77

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Activity

  1. lukehutch commented on May 28, 2024

    @lukehutch
    ContributorAuthor

    OK, so actually I do see the error on the console:

    [ERROR:flutter/runtime/ptrace_check.cc(75)] Could not call ptrace(PT_TRACE_ME): Operation not permitted
    Cannot create a FlutterEngine instance in debug mode without Flutter tooling or Xcode.
    
    To launch in debug mode in iOS 14+, run flutter run from Flutter tools, run from an IDE with a Flutter IDE plugin or run the iOS project from Xcode.
    Alternatively profile and release mode apps can be launched from the home screen.
    

    Is there some way to display this on the device screen as a pop-up dialog?

    Is there a fundamental reason why debug builds will never be manually launchable from the home screen?

  2. jonahwilliams commented on May 29, 2024

    @jonahwilliams
    Contributor

    Debug builds use the JIT dart VM. iOS does not allow applications to launch JIT (essentially by blocking combinations of writable + executable memory that a JIT would need to create), unless there is a debugger attached.

  3. lukehutch commented on May 29, 2024

    @lukehutch
    ContributorAuthor

    @jonahwilliams Thanks for explaining. Can Flutter just pop up a native error dialog on launch in this case? I have been trying for weeks to figure out why my app was crashing when launched from the home screen, and didn't see the console error until just now.

  4. jonahwilliams commented on May 29, 2024

    @jonahwilliams
    Contributor

    I thought we used to do that, but I don't know what happened to it. its possible it broke along the way, or perhaps there were other changes that required it to be removed. I'll label the issue for triage and let the iOS team fill in the details.

  5. changed the title [-]Crash when launching debug build from iOS home screen[/-] [+]iOS debug mode warning doesn't work anymore.[/+] on May 29, 2024
  6. jonahwilliams commented on May 29, 2024

    @jonahwilliams
    Contributor

    Possibly the problem is that we never hit this point because something fails during plugin initialization instead.

  7. lukehutch commented on May 29, 2024

    @lukehutch
    ContributorAuthor

    Well it is plugin registration that is failing, yes. Specifically GeneratedPluginRegistrant::registerWithRegistry fails because registrarForPlugin returns null, which is then passed to a non-nullable Swift parameter registry in the plugin's register(with:) method.

  8. stuartmorgan-g commented on May 29, 2024

    @stuartmorgan-g
    Contributor

    registrarForPlugin is annotated as nullable, so our generated registrant code is wrong; we should update it so that each line is a call to a static helper function that checks the registrar and no-ops if it's null.

  9. changed the title [-]iOS debug mode warning doesn't work anymore.[/-] [+]Plugin registration crash if registrar is `null`[/+] on May 29, 2024
  10. added
    toolAffects the "flutter" command-line tool. See also t: labels.
    P2Important issues not at the top of the work list
    triaged-iosTriaged by iOS platform team
    on May 29, 2024
  11. jmagman commented on May 29, 2024

    @jmagman
    Member

    [{{prefix}}{{class}} registerWithRegistrar:[registry registrarForPlugin:@"{{prefix}}{{class}}"]];

  12. adityadua24 commented on Aug 1, 2025

    @adityadua24
  13. randallli commented on Feb 27, 2026

    @randallli

    Just ran into this on Flutter 3.38.5 (stable) with an iPhone 13 Pro Max running iOS 26.2.1.

    The crash manifests in audioplayers_darwin (AudioplayersDarwinPlugin.register(with:) → swift_getObjectType on nil), but the root cause is exactly as described above — registrarForPlugin returns nil and GeneratedPluginRegistrant passes it through unchecked.

    I spent significant time investigating this, including fully regenerating the iOS project from scratch with flutter create to rule out my own configuration. Confirming that release and profile builds work fine when launched from the home screen — only debug builds crash when launched from the home screen without a debugger attached.

    Adding a null check in GeneratedPluginRegistrant (as @stuartmorgan-g suggested) or surfacing the existing ptrace error dialog before plugin registration would save developers a lot of debugging time. The current behavior — a raw SIGSEGV with no user-facing message — makes it very difficult to diagnose.

    Workaround for anyone else hitting this: use flutter run --release or flutter run --profile for standalone physical device testing. Debug builds must be launched via Xcode or flutter run, which attach the debugger that iOS requires for JIT execution. Debug builds launched from the home screen will always crash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listteam-iosOwned by iOS platform teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-iosTriaged by iOS platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions