'How to get readable stacktrace for Dart code exception with Firebase Crashlytics in Flutter app?
I've followed integration guide and integrated Firebase Crashlytics into my Flutter app.
When testing with FirebaseCrashlytics.instance.crash(); I expect to see a readable Dart stacktrace of the exception to know the line number at least. Instead i can see the following in Firebase:
Fatal Exception: io.flutter.plugins.firebase.crashlytics.FirebaseCrashlyticsTestCrash
This is a test crash caused by calling .crash() in Dart.
io.flutter.plugins.firebase.crashlytics.FlutterFirebaseCrashlyticsPlugin.lambda$crash$1 (FlutterFirebaseCrashlyticsPlugin.java:77)
io.flutter.plugins.firebase.crashlytics.-$$Lambda$FlutterFirebaseCrashlyticsPlugin$S7-ndFU6gs1AKgZZJXppPdTcLo8.run
android.os.Handler.handleCallback (Handler.java:883)
android.os.Handler.dispatchMessage (Handler.java:100)
android.os.Looper.loop (Looper.java:224)
android.app.ActivityThread.main (ActivityThread.java:7560)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:539)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:950)
Here are the integration changes:
"pubspec.yaml":
firebase_analytics: ^9.0.2
firebase_core: "^1.10.0"
firebase_crashlytics: ^2.4.0
"android.build.gradle":
buildscript {
...
dependencies {
...
classpath 'com.google.gms:google-services:4.3.10'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
...
"android/app/build.gradle":
...
// firebase
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
...
release {
signingConfig signingConfigs.googleplaySigningConfig
minifyEnabled true
debuggable false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.cfg'
firebaseCrashlytics {
mappingFileUploadEnabled true
nativeSymbolUploadEnabled true
strippedNativeLibsDir "build/app/intermediates/stripped_native_libs/release/out/lib"
unstrippedNativeLibsDir "build/app/intermediates/merged_native_libs/release/out/lib"
}
ndk {
debugSymbolLevel 'FULL'
}
}
...
Note i had to specify strippedNativeLibsDir and unstrippedNativeLibsDir as otherwise it failed with "Crashlytics could not determine unstripped native library directories for project ':app', variant Release. These are required".
"main.dart"
Future<void> main() async {
runZonedGuarded<Future<void>>(() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
// Pass all uncaught errors from the framework to Crashlytics.
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError;
...
FirebaseAnalytics.instance.setUserId(id: uuid);
FirebaseCrashlytics.instance.setUserIdentifier(uuid);
await FirebaseAnalytics.instance.setAnalyticsCollectionEnabled(true);
await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);
await FirebaseCrashlytics.instance.sendUnsentReports();
...
runApp(MyApp());
}, (error, stack) => FirebaseCrashlytics.instance.recordError(error, stack));
}
The app is build with flutter build appbundle.
In build log i can see:
[ ] Unable to extract native debug metadata from /Users/developer/Documents/dev/src/myapp/build/app/intermediates/merged_native_libs/release/out/lib/arm64-v8a/libapp.so because unable to locate the objcopy executable for the arm64-v8a ABI.
and libapp.so is stripped in both "merged_native_libs" and "stripped_native_libs". I was unable to find libapp.so which is not stripped.
BTW i leave only arm64 files:
...
defaultConfig {
applicationId "myapp"
minSdkVersion 24
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
ndk {
abiFilters "arm64-v8a" // to reduce all the other ARCHs except this
}
}
...
Is there anything i'm missing?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
