How to build APK with no sound null safety

Viewed 54304

I can run an app in release mode on my phone with passing flag --no-sound-null-safety --release, but neither flutter build apk --enable-experiment=non-nullable nor flutter build apk --no-sound-null-safety nor flutter build apk --enable-experiment=non-nullable --no-sound-null-safety will work

5 Answers

Just do this on your terminal

flutter build apk --split-per-abi --no-sound-null-safety

Or

flutter build apk --release --no-sound-null-safety

It was only necessary to use additional comment // @dart=2.9 before all imports in main.dart so it could run without any flags

So main.dart should look like this:

// @dart=2.9
import 'package:flutter/gestures.dart';
import 'package:flutter/widgets.dart';
import '../init.dart';

Future<void> main() async {
  GestureBinding.instance?.resamplingEnabled = true;
  WidgetsFlutterBinding.ensureInitialized();
  await init();
  runApp(MyApp());
}

Any other .dart files don't require annotating them

P.S. make sure you updated pubspec.yaml for using Dart 2.12:

environment:
  sdk: '>=2.12.0-0.0 <3.0.0'

we can try this,

 flutter build apk --release --no-sound-null-safety

or by adding in main.dart , 1st Line

 // @dart=2.9

flutter build apk --no-sound-null-safety

If You are facing no sound null safety problem then follow 3 Steps.

  1. // @2.9 in the top and remove the parameter from Const app_name();
  2. 2nd solution is run --no-sound-null-safety in the terminal
  3. Edit your Configure File and write in Additional run args:- --no-sound-null-safety

See these images 1 and 2.

Related