skip to Main Content

When trying to run my flutter program, i’m getting the following errors:

Unhandled exception:
    Null check operator used on a null value
    #0      Context.embedFlutterFrameworks
    (file:///Users/mustafa/flutter/packages/flutter_tools/bin/xcode_backend.dart:235:68)
    #1      Context.run
    (file:///Users/mustafa/flutter/packages/flutter_tools/bin/xcode_backend.dart:59:9)
    #2      main (file:///Users/mustafa/flutter/packages/flutter_tools/bin/xcode_backend.dart:17:5)
    #3      _delayEntrypointInvocation.<anonymous closure>
    (dart:isolate-patch/isolate_patch.dart:295:33)
    #4      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
    Command PhaseScriptExecution failed with a nonzero exit code

Flutter Doctor details:

[✓] Flutter (Channel master, 3.16.0-6.0.pre.46, on macOS 14.0 23A344 darwin-arm64, locale en-TZ)
    • Flutter version 3.16.0-6.0.pre.46 on channel master at /Users/mustafa/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 6dce1425e0 (43 minutes ago), 2023-10-09 09:10:25 -0400
    • Engine revision 664f5e8338
    • Dart version 3.3.0 (build 3.3.0-1.0.dev)
    • DevTools version 2.28.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /Users/mustafa/Library/Android/sdk
    • Platform android-33, build-tools 33.0.1
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

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

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

[✓] Android Studio (version 2022.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.6+0-17.0.6b829.9-10027231)

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

[✓] Connected device (3 available)
    • iPhone 15 Pro (mobile) • A78DD306-C05C-4547-A0E5-B87FBA654D3F • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-17-0 (simulator)
    • macOS (desktop)        • macos                                • darwin-arm64   • macOS 14.0
      23A344 darwin-arm64
    • Chrome (web)           • chrome                               • web-javascript • Google Chrome
      117.0.5938.149
[✓] Network resources
• All expected network resources are available.

• No issues found!

I am using a MacBook Air M1 running on Sonoma 14.0 and Xcode 15.0. I have tried clearing flutter cache, updating flutter and re-installing podfile but the error still persists.

2

Answers


  1. I have been experiencing this issue for a while. Downgrading to Flutter 3.13.9 resolved it:

    flutter downgrade
    flutter clean && flutter pub get
    pod repo update && pod install
    flutter run
    

    Probably that bug should be properly reported to Flutter GitHub.

    Login or Signup to reply.
  2. There seems to be an issue with the 3.16 flutter version, probably linked to the native_assets feature.

    In flutter/packages/flutter_tools/bin/xcode_backend.dart at line 231 it fails to get the environment variable FLUTTER_BUILD_DIR so the null check fails :

    final String flutterBuildDir = environment['FLUTTER_BUILD_DIR']!;
    

    Instead of downgrading it is possible as a work-around to modify this line to :

    final String flutterBuildDir = environment['FLUTTER_BUILD_DIR'] ?? 'build';
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search