Sub topic 11
Testing the release build on real devices
A release build can behave differently from the debug build you have used all along. This chapter covers what changes, how to install a release build on physical Android and iOS devices, which failures to look for, and how to read a crash report from an obfuscated build.
It assumes you can build release artifacts for both platforms, as covered in the earlier chapters. It also assumes you have at least one physical Android device with USB debugging enabled. On macOS, you also need an iPhone or iPad registered to your Apple developer account.
Why a release build needs its own test pass
Debug builds run Dart in a JIT (just-in-time) virtual machine with assertions enabled, hot reload hooks, and extra service extensions. Release builds are compiled ahead of time (AOT) to native code. The compiler removes unused code and assertions, and the Android toolchain may shrink and obfuscate what remains.
| Aspect | Debug | Release |
|---|---|---|
| Dart compilation | JIT | AOT, tree-shaken |
| `assert` statements | Run | Removed |
| Hot reload and DevTools debugging | Available | Not available |
| Android manifest overlay | `debug/AndroidManifest.xml` applies | Only `main/AndroidManifest.xml` applies |
| Android code shrinking (R8) | Off | On, if configured |
| Signing | Debug key | Your release or upload key |
| Performance | Slow, not representative | Representative |
Three categories of bugs only appear in release builds:
- Missing permissions or configuration. Something existed only in a debug-only file.
- Stripped code. Shrinking removed a class that is only reached through reflection or a native call.
- Signing mismatches. A service tied to a key fingerprint rejects the release key.
Running a release build on a device
The quickest way to get release behavior on a connected device is the --release flag:
# List connected devices and emulators
flutter devices
# Run in release mode on a specific device
flutter run --release -d <device-id>
# Install the most recent build without running a debugger session
flutter install -d <device-id>Release mode has no hot reload. Each change needs a full rebuild, so keep this for verification, not for day-to-day development.
Two platform differences matter:
- Android emulators can run release builds. iOS simulators cannot, because Flutter does not support release or profile mode there. For iOS, use a physical device.
- On iOS 16 and later, the device needs Developer Mode turned on (Settings > Privacy & Security > Developer Mode) before it accepts locally installed builds.
Check the mode from inside the app
Do not assume the build mode. A small diagnostic label prevents testing the wrong build:
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
const apiBaseUrl = String.fromEnvironment(
'API_BASE_URL',
defaultValue: 'https://staging.example.com',
);
String buildModeLabel() {
if (kReleaseMode) return 'release';
if (kProfileMode) return 'profile';
return 'debug';
}
void main() {
runApp(
MaterialApp(
home: Scaffold(
body: Center(
child: Text('Mode: ${buildModeLabel()}\nAPI: $apiBaseUrl'),
),
),
),
);
}Run it with flutter run --release --dart-define=API_BASE_URL=https://api.example.com. If the screen shows the staging URL, your define did not reach the build. That is a configuration bug you want to find before your testers do.
Testing the exact Android artifact you will upload
flutter run --release builds an APK for your device. Google Play receives an App Bundle (AAB), and Play generates device-specific APKs from it. To test what Play will actually deliver, use bundletool, Google's command-line tool for AABs. Install it separately, for example with Homebrew (brew install bundletool) or from its GitHub releases page.
flutter build appbundle --release
bundletool build-apks \
--bundle=build/app/outputs/bundle/release/app-release.aab \
--output=app.apks \
--ks=$HOME/upload-keystore.jks \
--ks-key-alias=upload \
--connected-device
bundletool install-apks --apks=app.apks--connected-device generates only the split APKs that match the attached device. Without --ks, bundletool signs with the debug keystore. That is fine for a smoke test, but it does not match the key you configured for release.
Signature conflicts on install
Android refuses to update an app when the signing key differs from the installed copy. The error looks like INSTALL_FAILED_UPDATE_INCOMPATIBLE. Uninstall the existing app first:
adb uninstall com.example.myappThis deletes the app's local data, so do it on test devices only.
The most common Android release failure: no internet
The Flutter project template declares the INTERNET permission only in android/app/src/debug/AndroidManifest.xml and android/app/src/profile/AndroidManifest.xml. This lets hot reload talk to the debugger. The release build merges only src/main, so an app that fetches data without trouble in debug can fail every request in release.
If your app makes network calls, make sure the main manifest declares the permission:
<!-- android/app/src/main/AndroidManifest.xml -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:label="My App"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<!-- activity declarations unchanged -->
</application>
</manifest>The symptom is a SocketException or a "Failed host lookup" error that appears only on release builds. Other permissions that you request at runtime, such as camera, location, or notifications, also need declarations in the main manifest. Test each one on a clean install.
Failures caused by shrinking and obfuscation
If you enabled R8 shrinking, it can remove or rename classes that are only reached through reflection or JNI. Plugins that ship their own consumer ProGuard rules are usually safe. Your own native Kotlin or Java code and some third-party SDKs are not. Typical symptoms are a ClassNotFoundException or NoSuchMethodError in adb logcat, or a feature that does nothing in release.
To investigate:
- Reproduce on a device with
adb logcatrunning, filtering for errors. - Find the class name in the exception.
- Add a keep rule to
android/app/proguard-rules.pro, for example-keep class com.example.sdk.** { *; }. - Rebuild and retest.
adb logcat *:E | grep -i -E "flutter|AndroidRuntime|ClassNotFound"Dart obfuscation does not cause these failures, because it only renames Dart symbols. It does make crash reports unreadable until you symbolize them.
Verifying that crash symbols work
Do this once per release pipeline, not once per release. Add a temporary crash, build with --obfuscate --split-debug-info=build/symbols, install it, and trigger the crash. Then copy the raw stack trace into a file and decode it:
flutter symbolize -i crash.txt -d build/symbols/app.android-arm64.symbolsThe symbols file name depends on the target architecture. On a 64-bit Android phone it is app.android-arm64.symbols. If the output shows readable function names and line numbers, your symbol archive matches the build. If it fails, the symbols belong to a different build. Archive the build/symbols directory for every upload, labeled with the version name and build number.
iOS-specific checks
Install through Xcode (Window > Devices and Simulators), through flutter run --release -d <device-id>, or through TestFlight for a build closest to what users get. A TestFlight install also tests the distribution signing and provisioning path, which a local install does not.
Check these on iOS:
- Launch from a cold start. Force-quit the app and open it from the home screen. A crash that happens only on cold launch often comes from plugin initialization.
- Permission prompts. A missing usage description such as
NSCameraUsageDescriptioninInfo.plistmakes the app crash the moment the permission is requested. - Push notifications and associated domains. These depend on the entitlements and provisioning profile, so they can work in a development build and fail in a distribution build.
- Background behavior. Suspend and resume the app, switch networks, and rotate the device.
A practical device checklist
Aim for coverage across device classes, not a large number of devices:
- One low-end Android phone with limited RAM. It exposes jank and memory problems.
- One recent Android phone on the newest OS version, and one on the oldest version you support.
- One iPhone on the oldest iOS version you support, and one on the newest.
- A tablet or foldable if your layout adapts to screen size.
On each device, run through sign-in, a network-dependent screen, offline launch (airplane mode), a runtime permission, a deep link, and an app update from the previous version. The update path matters because users upgrade over an existing install. Install the previous release, then install the new one over it, and confirm local data and stored sessions survive.
For performance questions, flutter run --profile gives release-like speed with DevTools connected. Use it to diagnose slow frames, then confirm the fix on a release build.
Exercise
Your app loads data from an API without problems when you run flutter run. After installing the release APK on a phone, every request fails with "Failed host lookup." Name the most likely cause and the file to fix.
Show answer
The INTERNET permission is declared only in the debug and profile manifests (android/app/src/debug/AndroidManifest.xml and android/app/src/profile/AndroidManifest.xml). The release build uses only android/app/src/main/AndroidManifest.xml, so add <uses-permission android:name="android.permission.INTERNET" /> there and rebuild.
Exercise
A release build installed from Google Play fails Google Sign-In, but the APK you built locally and installed with flutter run --release works. What is the likely reason, and where do you find the value you need?
Show answer
With Play App Signing, Google signs distributed apps with its own app signing key, not your upload key. The sign-in configuration holds only the upload key's fingerprint. Copy the SHA-1 or SHA-256 from Play Console under App integrity and register it with the sign-in service.
Exercise
You enabled --obfuscate --split-debug-info=build/symbols and a tester sends a stack trace full of hexadecimal addresses. How do you turn it into readable function names, and what must you have kept?
Show answer
Save the trace to a file and run flutter symbolize -i crash.txt -d build/symbols/app.android-arm64.symbols, using the symbols file that matches the device architecture. You must have archived the build/symbols output of the exact build the tester ran.