Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build APK with no sound null safety

Tags:

apk

flutter

dart

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

like image 250
Andrey Gritsay Avatar asked Dec 30 '20 09:12

Andrey Gritsay


2 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
like image 149
Adam Musa Avatar answered Sep 22 '22 14:09

Adam Musa


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'
like image 34
Andrey Gritsay Avatar answered Sep 23 '22 14:09

Andrey Gritsay