I saw a couple of duplicate questions in this similar topic. But those are either unanswered or outdated.
I've been trying to figure out what I'm missing for more than a week now and I couldn't make the crashlytics work in my flutter app.
To make sure the default setup works, I tried to create a demo app and followed the instructions to setup crashlytics by FlutterFire .
When I call the method crash()
to do a test-crash. The app crashed as expected and it was mentioned that the crash-logs are sent only on restarting the app. I opened the app again. But the firebase console showed the circular loader listening for first crash. (Heck! it crashed many times in the last 10 days )
Even when I fire a custom event, it didn't show in the analytics dashboard. Some forums said it might take upto 24 hours to update in the console. But it didn't show up even after 48 hours.
I'm totally clueless on what I'm doing wrong with the analytics/crashlytics setup. Any help here would be greatly appreciated.
Here are my configuration:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.5.1, on Microsoft Windows [Version 10.0.22000.282], locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] VS Code, 64-bit edition (version 1.60.0)
[✓] Connected device (3 available)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
...
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation platform('com.google.firebase:firebase-bom:29.0.0')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-crashlytics-ktx'
implementation 'com.android.support:multidex:2.0.1'
}
buildscript {
ext.kotlin_version = '1.5.31'
repositories {
google()
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.10'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.0'
}
}
allprojects {
repositories {
google()
mavenCentral()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/material.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError;
runApp(const MyApp());
}
void _incrementCounter() {
setState(() {
_counter++;
print("Counter incremented");
FirebaseCrashlytics.instance.log("Counter incremented to : $_counter");
FirebaseCrashlytics.instance.crash();
});
}
I still see the exception getting logged in the console. But that's where I doubt if things are configured correctly!
I see two exceptions! One for the test crash and the other one from the FirebaseCrashlytics
itself stating it couldn't handle the exception. I'm hoping thats the reason the logs are not uploaded to Firebase Console.
Are these two exceptions expected for a test-crash?
021-11-05 12:12:56.032 2055-2116/com.example.yetanotherdemo I/ResourceExtractor: Found extracted resources res_timestamp-1-1636094238693
2021-11-05 12:12:56.070 2055-2109/com.example.yetanotherdemo I/FA: App measurement initialized, version: 46000
2021-11-05 12:12:56.070 2055-2109/com.example.yetanotherdemo I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
2021-11-05 12:12:56.071 2055-2109/com.example.yetanotherdemo I/FA: To enable faster debug mode event logging run:
adb shell setprop debug.firebase.analytics.app com.example.yetanotherdemo
2021-11-05 12:12:56.113 2055-2055/com.example.yetanotherdemo I/zygote: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
2021-11-05 12:12:56.220 2055-2055/com.example.yetanotherdemo W/FlutterActivityAndFragmentDelegate: A splash screen was provided to Flutter, but this is deprecated. See flutter.dev/go/android-splash-migration for migration steps.
2021-11-05 12:12:56.334 2055-2109/com.example.yetanotherdemo I/FA: Tag Manager is not found and thus will not be used
2021-11-05 12:12:56.347 2055-2055/com.example.yetanotherdemo W/Activity: AppLock checkAppLockState locked:false verifying:false pkgName = com.example.yetanotherdemo isInMultiWindowMode:false showWhenLocked:false
2021-11-05 12:12:56.405 2055-2155/com.example.yetanotherdemo I/OpenGLRenderer: Initialized EGL, version 1.4
2021-11-05 12:12:56.615 2055-2160/com.example.yetanotherdemo I/flutter: Observatory listening on http://127.0.0.1:36753/BoWqFw1T8V8=/
2021-11-05 12:12:57.106 2055-2055/com.example.yetanotherdemo I/Choreographer: Skipped 44 frames! The application may be doing too much work on its main thread.
2021-11-05 12:12:57.166 2055-2055/com.example.yetanotherdemo I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
2021-11-05 12:13:00.942 2055-2065/com.example.yetanotherdemo I/zygote: Do partial code cache collection, code=28KB, data=28KB
2021-11-05 12:13:00.942 2055-2065/com.example.yetanotherdemo I/zygote: After code cache collection, code=28KB, data=28KB
2021-11-05 12:13:00.942 2055-2065/com.example.yetanotherdemo I/zygote: Increasing code cache capacity to 128KB
2021-11-05 12:16:08.586 2055-2118/com.example.yetanotherdemo I/flutter: Counter incremented
2021-11-05 12:16:08.647 2055-2055/com.example.yetanotherdemo E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.yetanotherdemo, PID: 2055
io.flutter.plugins.firebase.crashlytics.FirebaseCrashlyticsTestCrash: This is a test crash caused by calling .crash() in Dart.
at io.flutter.plugins.firebase.crashlytics.FlutterFirebaseCrashlyticsPlugin.lambda$crash$1(FlutterFirebaseCrashlyticsPlugin.java:77)
at io.flutter.plugins.firebase.crashlytics.-$$Lambda$FlutterFirebaseCrashlyticsPlugin$S7-ndFU6gs1AKgZZJXppPdTcLo8.run(Unknown Source:0)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:7025)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
2021-11-05 12:16:12.652 2055-2055/com.example.yetanotherdemo E/FirebaseCrashlytics: Error handling uncaught exception
java.util.concurrent.TimeoutException
at com.google.firebase.crashlytics.internal.common.Utils.awaitEvenIfOnMainThread(Utils.java:138)
at com.google.firebase.crashlytics.internal.common.CrashlyticsController.handleUncaughtException(CrashlyticsController.java:233)
at com.google.firebase.crashlytics.internal.common.CrashlyticsController$1.onUncaughtException(CrashlyticsController.java:155)
at com.google.firebase.crashlytics.internal.common.CrashlyticsUncaughtExceptionHandler.uncaughtException(CrashlyticsUncaughtExceptionHandler.java:55)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1063)
at java.lang.Thread.dispatchUncaughtException(Thread.java:1955)
Firebase is not able to detect your crashes because you are running a debug build, so try the following:
1- Make sure you applied the mentioned steps for Android & iOS here
2- Run your app in release mode on a real device using the following commands as an examples:
flutter run --release
flutter run --release --no-sound-null-safety
3- Let your app make the crash 2 times
Hope that's gonna help you
And dont know about the crashlytics but for analytics custom event, I have followed these steps. I have used firebase_analytics and get_it(for state management) packages.
This is my main.dart
void main() {
setupLocator();
runApp(MyApp());
}
GetIt locator = GetIt.instance;
void setupLocator() {
if (!locator.isRegistered<AnalyticsService>()) {
locator.registerLazySingleton(() => AnalyticsService());
}
}
And in your MaterialApp add these
FirebaseAnalytics _analytics = FirebaseAnalytics();
FirebaseAnalyticsObserver getAnalyticsObserver() =>
FirebaseAnalyticsObserver(analytics: _analytics);
MaterialApp(
home: MyAppHome(),
navigatorObservers: [
locator<AnalyticsService>().getAnalyticsObserver(),
],
);
Whenever you want to log an event call this sendAnalyticsEvent function
Future sendAnalyticsEvent({String userEmail, bool platform})
async {
await _analytics.logEvent(
name: 'Informations',
parameters: <String, dynamic>{
'userEmail': userEmail,
'isAndroid': (platform == true)? 'Android' : 'IOS',
},
);
}
Then please make sure the event are triggered in DebugView. For enabling trigger event in debugView try this command in command line.
adb shell setprop debug.firebase.analytics.app <package_name>
Then you have do https://stackoverflow.com/a/69786358/11445727 these steps to get the data in dashboard.
Let me know if it works for you.
It reads TimeoutException
...which hints for crashing it at the wrong time (this only applies for the first crash). Let the application start up first, then crash it with button later. Besides, the logs are being uploaded instantly, while being online - on next startup is only the case, when it crashes while being offline.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.