flutter android app freezes on the splash screen in release mode

Viewed 1886

I have a problem using the storage to persist the user login data .

the scenario like that : after login , I clear the app and try to reopen it again , sometimes it open and sometimes it's freezes on the splash screen. this only happen in the release mode .

I tried to remove every package until I found the problem with using the storage after login. so I if I not login nothing freezes .

I used get_storage and shared_preferences and secured_storage packages but nothing changed . flutter 2.10.2.

tested on real device

also this the the used packages

module:
  androidX: true # Add this line.

environment:
  sdk: ">=2.11.0 <3.0.0"

dependencies:
  dio: ^4.0.0
  get: ^4.1.4
  get_storage:
  flutter:
    sdk: flutter


dev_dependencies:
  flutter_launcher_icons: ^0.9.2

flutter_icons:
  android: true
  ios: false
  image_path: "assets/icons/launcher_icon.png"
  flutter_test:
    sdk: flutter

name: delivery
description: manager App
version: 1.6.3
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

finally I decided to share the verbose hope someone can help

https://github.com/flutter/flutter/issues/98862

7 Answers

I had the same problem in our production app few days back. I released an update (where just a couple of tables were updated in the local app database) with Flutter 2.10.2 and many users started getting frozen launch screen.

After spending days trying to solve it, I finally downgraded the Flutter to 2.8 and released an update and the issue was gone.

You could install sentry_flutter in your application to capture exceptions in your release app.

Also, try moving flutter_native_splash: ^2.0.4 from dev_dependencies to dependencies.

I had a similar bug:

  • By default on Android, android:allowBackup is set to true which means that your app's data is automatically backed up to your Google Drive
  • The problem is when something in your data structure changes but you have an old backup with an old and incompatible data structure. When reinstalling a new version of the app which is incompatible with the old data structure which was backed up, it will freeze on the native splash screen.

I solved this by adding android:allowBackup="false" to android/app/src/main/AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    ...
    <application
        ...
        android:allowBackup="false"
        ...
    </application>
</manifest>

Take you real device and connect it to you pc via cable and install release version of you app

  1. Go-to terminal and run flutter logs to see what's going on

  2. In some cases, may be permissions are reason. You need to specify them (don't relax because of default permissions set)

I think there should be 2 things --

first make sure you added the Internet permission and other required permissions in AndroidManifest.xml file

Second if you already defined all the required permissions then try this--

in your app/build.gradle file add these 3 lines

        minifyEnabled false
        useProguard false
        shrinkResources false

in

buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
            minifyEnabled false
            useProguard false
            shrinkResources false
        }
    }

then clean your project and try again I hope this will work and if you still faced that problem check the documentation again of flutter_native_splash package you used, also watch the video of Johannes Milke's tutorial which is already linked in the documentaion.

Thankyou.

Since the other answers haven't given any luck, I would suggest that you start by disabling everything in your app, and gradually enable portions of the app until you reproduce the problem. For example, start by replacing your MyApp() in your main() with a blank shell of an app:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
    statusBarColor: Colors.transparent, // transparent status bar
  ));
  await initServices();
  runApp(MaterialApp(
    home: Container(color: Colors.blue),
  ));
}

This will tell you if the problem is in your initialization or the rest of your app. If the blue screen loads, it tells you that the initialization is fine. Keep dividing your app like this until you find the part this is causing the app to hang.

I recommend you to install the flutter sdk again from scratch and try it.

Related