Flutter APK file is showing only gray screen

171 views Asked by At

My APK file is showing only gray screen but it works well in debug mode.

Flutter Doctor (Edit):

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.8.0, on Microsoft Windows [Version 10.0.19043.1415], locale ko-KR)
[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[√] Chrome - develop for the web
[√] Android Studio (version 2020.3)
[√] VS Code (version 1.63.2)
[√] Connected device (3 available)

• No issues found!

main.dart:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  await Hive.initFlutter();
  await Hive.openBox("myBox1");
  SystemChrome.setPreferredOrientations(
    [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]
  ).then((_) => runApp(const MyApp()));
}

AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET"/>

What is causing this problem?

1

There are 1 answers

2
Youngermaster On

did you already try to finish the Android Toochain setup? I mean, it says that you don't have the cmdline-tools component and you didn't accepted the android licenses.

It says that you have the Android Studio Installed, so the only thing that you have to do is to:

  • Locate the SdkManager (it depends of your O.S.), then you will run something like this: ./sdkmanager --install "cmdline-tools;latest".
  • After that, you just accept the Android licenses, like this: flutter doctor --android-licenses (note, I suggest to to restart the console after the the previous step, and then try this command).

Note: I wanted to add this to the comment section, although I don't have the required reputation.

If that doesn't solve the problem I think that maybe is due to the line with the SystemChrome stuff.

So I would recommend to test it instead of this:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  await Hive.initFlutter();
  await Hive.openBox("myBox1");
  SystemChrome.setPreferredOrientations(
    [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]
  ).then((_) => runApp(const MyApp()));
}

With this:


import 'package:flutter/foundation.dart' show kIsWeb;

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  await Hive.initFlutter();
  await Hive.openBox("myBox1");
  if (kIsWeb) {
    // running on the web!
    SystemChrome.setPreferredOrientations(
      [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]
    ).then((_) => runApp(const MyApp()));
  } else {
    // NOT running on the web! You can check for additional platforms here.
    runApp(const MyApp()));
  }
  
}

There is a global boolean kIsWeb which can tell you whether or not the app was compiled to run on the web.

Documentation: https://api.flutter.dev/flutter/foundation/kIsWeb-constant.html

You can check more about that on this StackOverflow question.

I hope that was helpful .