Send Crashlytics reports from Android instrumented tests - android

I'm running my instrumented tests on Firebase Test Lab and want non-fatal exceptions to be reported to Crashlytics.
However, calling Crashlytics.logException() doesn't send the report immediately. After enabling core.debuggable(true) I see this when sending report:
D/CrashlyticsCore: Crashlytics is logging non-fatal exception "java.lang.Throwable: java.lang.Throwable" from thread main
But the report is not visible on Crashlytics dashboard until I restart the app, and then I see:
D/CrashlyticsCore: Checking for crash reports...
D/CrashlyticsCore: Found crash report /data/user/0/.../files/.Fabric/com.crashlytics.sdk.android.crashlytics-core/nonfatal-sessions/....cls
D/CrashlyticsCore: Attempting to send 1 report(s)
D/CrashlyticsCore: Adding single file ....cls to report ...
D/CrashlyticsCore: Sending report to: https://reports.crashlytics.com/spi/v1/platforms/android/apps/org.dasfoo.delern.instrumented/reports
D/CrashlyticsCore: Create report request ID: null
D/CrashlyticsCore: Result was: 202
I/CrashlyticsCore: Crashlytics report upload complete: ...
D/CrashlyticsCore: Removing report at /data/user/0/.../files/.Fabric/com.crashlytics.sdk.android.crashlytics-core/nonfatal-sessions/....cls
D/CrashlyticsCore: Checking for crash reports...
D/CrashlyticsCore: No reports found.
This is not ideal for production use cases, but it will at least work when user restarts the app. In tests, this never works because Firebase Test Lab does not restart the app (restarting the app means tests will fail).
Is there any workaround to allow Crashlytics to send non-fatal reports from the instrumented tests?
Used packages:
com.crashlytics.sdk.android:crashlytics:2.6.8#aar
io.fabric.tools:gradle:1.24.0
UPD: rephrased the question and title. I am looking for an option to alter Crashlytics default behavior, since it seems like a reasonable feature to have.

There isn't a way to report non-fatal events in the current session. The app needs to be restarted for non-fatal events to get reported to Crashlytics.

import com.google.firebase.crash.FirebaseCrash;
FirebaseCrash.report(new Exception("Error in CreateMobileAlertNative "+e.getStackTrace()));
I used to get non-fatal exception on crashlytics by using this FirebaseCrash class, I put some codes on my catch,via which i used to get those reports, try this once.

Related

Firebase Crashlytics : Settings request failed - After migrate from fabric

After I migrate to crashlytics from fabric, crash reports does not shown on Firebase console anymore.
I followed upgrade document for migration.
I tried force crash to test and i logged with adb logcat -s FirebaseCrashlytics, I noticed an error with reading settings.
FirebaseCrashlytics: Settings request failed.
09-29 16:09:56.619 683 721 D FirebaseCrashlytics: Requesting settings from https://firebase-settings.crashlytics.com/spi/v2/platforms/android/gmp/1:657730209335:android:0f0486036fa5647e/settings
09-29 16:09:56.619 683 721 D FirebaseCrashlytics: Settings query params were: {instance=23c94567f3a0450c2c4276ef9c4f083d3e073ab9, build_version=714012888, display_version=7.14.0.128, source=1}
09-29 16:09:56.641 683 721 E FirebaseCrashlytics: Settings request failed.
Here is my settings.
{"settings_version":3,"cache_duration":86400,"features":{"collect_logged_exceptions":true,"collect_reports":true,"collect_analytics":false,"prompt_enabled":false,"push_enabled":false,"firebase_crashlytics_enabled":false},"app":{"status":"activated","update_required":false,"report_upload_variant":2,"native_report_upload_variant":2},"fabric":{"org_id":"5e00a1546bfe67fb08000062","bundle_id":"com.univera.android"}}
firebase_crashlytics_enabled" status false in settings.
Crashlytics enabled on console.
I m using version 17.2.1 implementation 'com.google.firebase:firebase-crashlytics:17.2.1' and i enabled CrashlyticsCollection FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true);
Why firebase_crashlytics_enabled" status false in my settings and whats wrong about settings request.
Does anyone see the raports on firebase console after migrate from fabric ?
Your app must execute the following line to initialize Firebase at start-up:
FirebaseApp.initializeApp(getContext());
Also, you may want to set a user id so that crashes are tagged with the user id in the Firebase console:
FirebaseAnalytics mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
mFirebaseAnalytics.setUserId("yourUserTag");
I faced the same issue, having this error :
E/FirebaseCrashlytics: Settings request failed.
java.net.SocketException: socket failed: EPERM (Operation not permitted)
This was a device specific issue. I have this error on a Xiaomi Mi A3, but when I launched the app on an emulator I had no error and the crashes appeared well in crashlytics.
There is no need to initialize Firebase in your code as matdev said.
Try running your app on a different device or emulator and see if the problem persists.
I fixed this issue by adding firebase-settings.crashlytics.com to allow domain list in network-security-config
This may help
https://stackoverflow.com/a/70858796/8499308

Crashlytics class not recognized with Firebase Crashlytics SDK

With the Firebase Crashlytics SDK, the documentation explains how you can
force a crash
However, in the line:
Crashlytics.getInstance().crash();
Crashlytics is unrecognized and cannot be imported.
I tried switching to FirebaseCrashlytics.getInstance() but there is no crash() method.
Note: Crashlytics is indeed set up properly - I am able to cause my own crash by looking up a view that does not exist and it is reported correctly.
We have deprecated the force crash method in the new SDK. One example of a way to force a crash is manually throwing an exception
throw new RuntimeException("This is a crash");

Firebase Crashlytics and NDK Native Crashes

I have been trying to get Crashlytics to capture native/fatal/C++ crashes for our Unity project. I was able to get it to work for iOS without much effort. Also, it works for non-fatal exceptions in Android. I see the exceptions on the Console. However, if I crash the app from C++ code (e.g segmentation violation or raising a signal), I do not have any crash logged in the console.
To have native crashes working, I started by just adding a dependency on the CrashlyticsNDK .aar (com.crashlytics.sdk.android.crashlytics-ndk-2.1.0), but no luck. Searching on the internet, I found that I might need initialize Fabric myself. So I added the meta-data line in the manifest to disable automatic initialization, and added the following code in our Activity.onCreate():
Fabric.with(this, new Crashlytics(), new CrashlyticsNdk());
I see in the logs that auto-initialization is skipped. Still, no fatal crash being logged in the console.
I decompiled all those .aar files to try to understand what's going on. I found that whenever we disable auto-initialization, io.fabric.sdk.android.Fabric.java goes through a whitelisting logic that removes the CrashlyticsNdk kit from the list! It prints the following message in the logs:
08-01 22:07:14.278: W/Fabric(20797): Fabric will not initialize any kits when Firebase automatic data collection is disabled; to use Third-party kits with automatic data collection disabled, initialize these kits via non-Fabric means.
Then, I tried to hack the Fabric initialization by pretending the data collection is on during initialization only, as follow:
DataCollectionArbiter.getInstance(this).setCrashlyticsDataCollectionEnabled(true);
Fabric.with(this, new Crashlytics(), new CrashlyticsNdk());
Fabric.getLogger().i("MyCrashlyticsInit", "My crashlytics initialization successful");
DataCollectionArbiter.getInstance(this).setCrashlyticsDataCollectionEnabled(false);
Now, I can see some interesting log lines:
08-01 22:45:39.356: I/FirebaseInitProvider(24353): FirebaseApp initialization successful
08-01 22:45:39.362: I/CrashlyticsInitProvider(24353): CrashlyticsInitProvider skipping initialization
08-01 22:45:39.404: D/libcrashlytics(24353): Initializing libcrashlytics version 2.0.5
08-01 22:45:39.404: D/libcrashlytics(24353): Initializing native crash handling successful.
08-01 22:45:39.419: I/CrashlyticsCore(24353): Initializing Crashlytics Core 2.7.0.33
08-01 22:45:39.427: I/MyCrashlyticsInit(24353): My crashlytics initialization successful
So, when I crash the app and run it again, I get the log line below:
08-01 22:45:39.489: W/CrashlyticsCore(24353): Received null settings, skipping report submission!
I have the impression the crash was handled correctly, but Crashlytics could not upload the crash data because of invalid/null settings.
I would appreciate if someone could help me with this. Getting Crashlytics to work has to be much simpler, and I have the feeling I've done something wrong along the way.
Thanks in advance, and sorry if I was too verbose. Just wanted to show the whole context.

Firebase Crashlytics not reporting crashes when manually enabled

Crashlytics works just fine without opt-in reporting. But it stops reporting anything as soon as I set up opt-in reporting according to the tutorial.
Specifically, I added the following content to AndroidManifest.xml
<meta-data
android:name="firebase_crashlytics_collection_enabled"
android:value="false" />
And I added the following into the onCreate:
Fabric.with(this, Crashlytics())
With a debugger, I am sure that the above line has been executed.
However, nothing is reported to the Crashlytics. Instead, the logger gives the following,
D/Fabric: Falling back to Crashlytics key lookup from Manifest
D/Fabric: Falling back to Crashlytics key lookup from Strings
D/Fabric: Generating Crashlytics ApiKey from google_app_id in Strings
D/Fabric: Using AdvertisingInfo from Preference Store
D/Fabric: Falling back to Crashlytics key lookup from Manifest
D/Fabric: Falling back to Crashlytics key lookup from Strings
D/Fabric: Build ID is: ...
D/CrashlyticsCore: Crashlytics is disabled, because data collection is disabled by Firebase.
D/Fabric: Initializing io.fabric.sdk.android:fabric [Version: 1.4.6.29], with the following kits:
com.crashlytics.sdk.android:crashlytics [Version: 2.9.7.29]
com.crashlytics.sdk.android:beta [Version: 1.2.10.27]
com.crashlytics.sdk.android:answers [Version: 1.4.5.29]
com.crashlytics.sdk.android.crashlytics-core [Version: 2.6.6.29]
D/Fabric: Not fetching settings, because data collection is disabled by Firebase.
D/Fabric: Falling back to Crashlytics key lookup from Manifest
D/Fabric: Falling back to Crashlytics key lookup from Strings
D/Fabric: Build ID is: ...
D/Fabric: Analytics collection disabled, because data collection is disabled by Firebase.
D/Fabric: Could not get parcel from Google Play Service to capture AdvertisingId
D/Fabric: Could not get parcel from Google Play Service to capture Advertising limitAdTracking
D/Fabric: AdvertisingInfo not present
D/Fabric: Asychronously getting Advertising Info and storing it to preferences
I have noticed this interesting line: D/CrashlyticsCore: Crashlytics is disabled, because data collection is disabled by Firebase. which is probably the cause of the issue. Yet I can't find any information about this log.
There is an issue with Firebase Crashlytics 2.9.7 preventing opt-in reporting as described in the documentation to work: the start of Crashlytics from code will not be performed.
For the time being downgrading to 2.9.6 will enable your code to work properly.
Please follow this answer
https://stackoverflow.com/a/59906454/6743289
For those wish to use crashlytics for their android app who haven't been using crashlytics of fiber.io, there are certain changes in the way you FirebaseApp is initialized which you will find in the above link.
Use following dependencies for android.
Paste it into build.gradle app:
implementation('com.crashlytics.sdk.android:crashlytics:2.9.6#aar') {
transitive = true
}
Upgrade it from 2.9.5 to 2.9.6.
It works for me.
Add this line into Application class
Fabric.with(this, Crashlytics())
Crashlytics 2.9.8 has been released which fixes the bug. I've tested to confirm. The changelog:
2.9.8 December 21, 2018
Fixed bug with firebase_crashlytics_collection_enabled flag that erroneously disabled data collection under some circumstances.
Initialization of app is not mentioned anywhere to get crashlytics report on our console!
Step 1. First follow the official doc's link to include all dependencies as it is given there and setup your firebase app through firebase console.
Step 2. Now do the following initialization in your base application class or base activity class.
FirebaseApp.initializeApp(getApplicationContext());
FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true);
Now clean you project and do some force crash for few times, you should be able to see your crashlytics report on your firebase console

Fabric Crashlytics for Android not working

I’ve followed the installation tutorial step by step for an Android app.
All seems fine, but after a couple of hours I don’t get to enter the dashboard (always redirected to the installation tutorial).
I guess that means my app have not been detected yet. It is supposed to be ready after a few minutes.
Enabling debug mode, everything looks good:
06-01 10:56:12.697 9871-9899/com.mypackage.test.desa D/CrashlyticsCore: Attempting to send crash report at time of crash...
06-01 10:56:12.837 4410-9967/? E/SQLiteLog: (284) automatic index on crash_info_summary(package_name_touched)
06-01 10:56:13.067 989-3341/? W/ActivityManager: Scheduling restart of crashed service com.sec.android.app.videoplayer/.videowall.TranscodeService in 1000ms
06-01 10:56:13.787 989-1335/? W/ActivityManager: Scheduling restart of crashed service com.sec.android.widgetapp.at.hero.accuweather/.WeatherClockScreenService in 10276ms
06-01 10:56:13.787 989-1335/? W/ActivityManager: Scheduling restart of crashed service com.sec.android.widgetapp.at.hero.accuweather/.WeatherClockService in 20275ms
06-01 10:56:14.507 9871-9899/com.mypackage.test.desa D/CrashlyticsCore: Adding single file 592FD68C000C-0001-268F-1112AA20B096.cls to report 592FD68C000C-0001-268F-1112AA20B096
06-01 10:56:14.507 9871-9899/com.mypackage.test.desa D/CrashlyticsCore: Sending report to: https://reports.crashlytics.com/spi/v1/platforms/android/apps/com.minsait.visitaunica.desa/reports
06-01 10:56:14.977 9871-9899/com.mypackage.test.desa D/CrashlyticsCore: Create report request ID: null
06-01 10:56:14.977 9871-9899/com.mypackage.test.desa D/CrashlyticsCore: Result was: 202
06-01 10:56:14.977 9871-9899/com.mypackage.test.desa I/CrashlyticsCore: Crashlytics report upload complete: 592FD68C000C-0001-268F-1112AA20B096
06-01 10:56:14.977 9871-9899/com.mypackage.test.desa D/CrashlyticsCore: Removing report at /data/data/com.minsait.visitaunica.desa/files/.Fabric/com.crashlytics.sdk.android.crashlytics-core/fatal-sessions/592FD68C000C-0001-268F-1112AA20B096.cls
Any help would be appreciated.
Thank you in advance.
Finally, it seems that the issue was a wrong internal state in their DB. Also happened 2 more times with other projects.
Contacting the support team was the solution. They replied very quickly and were very kind by the way.
I had a similar problem; even though you haven't added the fabric, apparently you have to remove it within the manifest:
<meta-data
tools:node="remove"
android:name="io.fabric.ApiKey"/>
Firstly, I always recommend installing Fabric.io using the build in IDE plugin.
You can find out how to install that here:
https://fabric.io/downloads/android

Categories

Resources