Cannot run with sound null safety because dependencies don't support null safety

256,105

Solution 1

First, you should read through the guide to understand unsound null safety. If you are sure that you want to run your application with unsound null safety, you can use the following command:

flutter run --no-sound-null-safety

The --no-sound-null-safety option is not documented in the article, however, I have not experienced any problems with it for the last few months (and especially not since the whole Flutter framework has been migrated to null safety).

The documentation has now been updated to include this. See Testing or running mixed-version programs.

IDE run arguments/configuration

To set this up in your IDE of choice, you can use:

  • In IntelliJ/Android Studio: "Edit Configurations" (in your run configurations) → "Additional run args".
  • In Visual Studio Code: search for "Flutter run additional args" in your user settings.

In both cases, add --no-sound-null-safety.

Test configuration

For tests, you will want to do the same thing:

  • In IntelliJ/Android Studio: "Edit Configurations" (in your run configurations) → "Additional args".
  • In Visual Studio Code: search for "Flutter test additional args" in your user settings.

In both cases, add --no-sound-null-safety.

Solution 2

In Android Studio:

Run → Edit ConfigurationsAdd Additional Run args--no-sound-null-safety

Enter image description here

Solution 3

If using Visual Studio Code, create file .vscode/launch.json in the project root and add:

"args": [
         "--no-sound-null-safety"
        ]

Complete code:

{
        // Use IntelliSense to learn about possible attributes.
        // Hover to view descriptions of existing attributes.
        // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
        "version": "0.2.0",
        "configurations": [
                {
                        "name": "YOUR_PROJECT_NAME",
                        "program": "lib/main.dart",
                        "request": "launch",
                        "type": "dart",
                        "args": [
                                "--no-sound-null-safety"
                            ]
                }
        ]
}

Solution 4

If you are using Visual Studio Code, then go to:

  • Menu FilePreferencesSettings

  • Search for "Flutter run additional args"

  • Then click Add Item

  • Now type --no-sound-null-safety

  • Click OK.

Solution 5

You run into this error if your code is not fully migrated to null-safety. You can run your "mixed-version" code:

  • Using the Android Studio IDE

    Copy: --no-sound-null-safety

    Enter image description here

    enter image description here

  • In the Dart file

    Add // @dart=2.9 at the top in your main.dart file and run the app using the Play ► icon.

    // @dart=2.9
    import 'package:flutter/material.dart';
    
    void main() {
      //...
    }
    
  • Using the command line

    flutter run --no-sound-null-safety
    

    Or to be specific (say in Chrome)

    flutter run -d chrome --no-sound-null-safety
    
Share:
256,105
creativecreatorormaybenot
Author by

creativecreatorormaybenot

Updated on July 08, 2022

Comments

  • creativecreatorormaybenot
    creativecreatorormaybenot almost 2 years

    I have followed "Enabling null safety" on dart.dev and also migrated my whole Flutter application to null safety.

    Now, I am trying to run it using flutter run. However, it will not start because of the following error:

    Error: Cannot run with sound null safety, because the following dependencies
    don't support null safety:
    
     - package:cloud_firestore_web
     - package:firebase_core_web
     - package:shared_preferences
     - package:url_launcher_web
     - package:firebase_auth
     - package:http
     - package:provider
    ...
    
    For solutions, see https://dart.dev/go/unsound-null-safety
    Failed to compile application.
    

    The guide at the URL says that I should "wait for dependencies to migrate before you migrate your package", but I want to use non-nullable by default (NNBD) now.

    How can I do that?

  • creativecreatorormaybenot
    creativecreatorormaybenot over 3 years
    @ChiragArora you can add it to the additional arguments in your run configuration (click on the dropdown where it says main.dart next to the device and then on "Edit configurations").
  • Dolphin
    Dolphin over 3 years
    it it possible add fastlane build with no-sound-null-safety parameter? @creativecreatorormaybenot
  • Dolphin
    Dolphin about 3 years
    not works in flutter 2.2.x when build a ios package @creativecreatorormaybenot stackoverflow.com/questions/67914266/…
  • Dolphin
    Dolphin about 3 years
    in flutter 2.2.x when build ios it works? @issac stackoverflow.com/questions/67914266/…
  • Dexter Fury Kombat Zone
    Dexter Fury Kombat Zone about 3 years
    Thanks Worked for me
  • GtdDev
    GtdDev almost 3 years
    In my case, I have added " // @dart=2.9"; however, in TEST\main.dart
  • Trophy Developers
    Trophy Developers almost 3 years
    This didn't work " dC:\src\flutter\flutter\flutter>flutter run --no-sound-null-safety Downloading Web SDK... 120.8s Error: No pubspec.yaml file found. This command should be run from the root of your Flutter project." but a configuration worked : Run --> Edit Configurations --> Add Additional Run args --> --no-sound-null-safety
  • n13
    n13 almost 3 years
    Saved my life with the VSCode tip - also setting Flutter test additional args (note "test"!!) - that makes the unit tests work. Thanks!
  • Ayush Oli
    Ayush Oli over 2 years
    That would be a correct answer if it was for Flutter Test. But if you are getting an error while running that you should add the Additional Args for Flutter Run. so search for Flutter Run in Settings. and then add like above one.
  • ege men
    ege men over 2 years
    a more example, this work for me: flutter build apk --release --no-sound-null-safety
  • Harjinder Bains
    Harjinder Bains over 2 years
    Thanks for this solution. it worked for me