The problem
While working on a clientâs mobile app, the customer support team reported that there are one or two users who are seeing a blank white screen when they open the app. I somehow understood that something in the main.dart
file was throwing an exception until the runApp
method is raeched and as a result there was the blank white screen. But, there was no details on how to reproduce the issue either on debug mode or release mode.
Time passed, and someone internally from the company reported the same issue on their test Android device. I asked them to hand over the device to me so that I can -which at the moment I didnât know how to- debug the issue. After getting the device, I remembered that using Android Studioâs Logcat can be useful for finding out whatâs happening when the app is launched.
Using Android Studio Logcat
Logcatâs official definition is:
âThe Logcat window in Android Studio helps you debug your app by displaying logs from your device in real time â for example, messages that you added to your app with the Log class, messages from services that run on Android, or system messages⊠When an app throws an exception, Logcat shows a message followed by the associated stack trace containing links to the line of code.â.
Here Iâll show you how I used to debug my Flutter app on release mode and find the issue that was causing the blank white screen on app launch and how you can use it too if not for the same issue, for any other issue you might face in the future.
First, open your Flutter appâs /android
folder in Android Studio:
Then, connect your Android device to your computer via USB cable and open the panel by clicking on the âLogcatâ tab at the bottom of the Android Studio window:
The first time you open the panel, youâll see a terminal-like screen with a lot of logs. So much so that every second, multiple logs are being printed and itâs hard to keep track of whatâs what:
You can use the search bar at the top to filter logs by the package name of your app. In my case, the package name was az.cib.app
:
Also, filtering logs can be done by searching for package:mine
which will filter logs by the package name of the app that is currently opened on the Android Studio:
After connecting the device and filtering the logs, I killed the app and then reopened it to see if there are any logs on the launch of the app:
There I saw a log that gave me a hint about what might be causing the issue:
keystore2::security_level: In generate_key. 10533, Some("az.cib.app.FlutterSecureStoragePluginKey")
From the log, I understood that the error was connected to the flutter_secure_storage
plugin and in main.dart
file where I read a value from the FlutterSecureStorage
it might throwing an exception, thus not reaching the runApp
method.
Then I searched on the issues of the flutter_secure_storage
plugin on its GitHub repository to see if there are any issues mention any of the logs I saw:
Of those issues, one was exactly the same as the issue I was facing: âApp built in release mode does not start #53â
I found the solution to the issue in the comments of the issue:
Implemented the solution and the app started running without a blank white screen both on debug and release modes on the same device.
Conclusion
I canât think of any other similarly impossible-to-reproduce issues that will happen on few devices and only on release mode. But, having the knowledge of how to use Android Studio Logcat might be useful for other issues you might face in the future.