Skip to content

🐞 Debugging Flutter apps on release mode with Android Studio Logcat

 at 

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.



Subscribe to the newsletter
Kamran Bekirov

I'm Kamran Bekirov
Built over 70 mobile apps.
Building UserOrient for Flutter
Solo apps: LibroKit, Beyt
Packages: logarte, versionarte
Reach: X, LinkedIn, Instagram, GitHub