I am trying to link Firebase Analytics to my Unity application and build to Android. My build works and I am able to initialize Firebase + Firebase Analytics and send events, but I cannot see anything in the Firebase Analytics Dashboard (says 0 users active in the last 30 minutes, no events are logged, etc.)
Here is where I initialize Firebase in my application, following their documentation:
private void InitializeFirebase ()
{
FirebaseApp.CheckAndFixDependenciesAsync()
.ContinueWith(
continuationAction: (Task<DependencyStatus> task) =>
{
DependencyStatus dependencyStatus = task.Result;
if (dependencyStatus == DependencyStatus.Available)
{
_FirebaseApp = FirebaseApp.DefaultInstance;
FirebaseAnalytics.SetAnalyticsCollectionEnabled(enabled: true);
_LoggingManager.Logger?.Info(content: "Firebase App ready");
DisplayAnalyticsInstanceId();
}
else
{
_LoggingManager.Logger?.Error(
content: "Could not resolve all Firebase dependencies: " + dependencyStatus);
// Firebase Unity SDK is not safe to use here.
}
});
}
And here's where I log a sample event:
private void SendCompletedEvent (CompletedEvent playerEvent)
{
_Logger.Warning(content: "Sending event complete event");
DisplayAnalyticsInstanceId();
Firebase.Analytics.FirebaseAnalytics
.LogEvent(name: Firebase.Analytics.FirebaseAnalytics.EventComplete);
}
I build an APK using Unity Cloud Build, and because it doesn't use the latest version of XCode, I have downgraded my Firebase version to 8.1.0. In my adb logs, I see these calls go out (all at their appropriate times):
06-30 16:25:34.195 17977 18038 I Unity : Firebase Analytics API Initializing
06-30 16:25:34.195 17977 18038 I Unity : analytics API Initialized
06-30 16:25:34.410 17977 18216 I Unity : Firebase App ready
06-30 16:27:28.310 17977 18038 W Unity : Sending event complete event
So all of these functions are definitely firing, and from what I can tell nothing is complaining. Occasionally, even before I start the program, I do get these errors in adb logs:
06-27 15:28:14.770 1305 10260 W FA : Failed to retrieve Firebase Instance Id
However, I've also been logging my Firebase instance id using the FirebaseAnalytics.GetAnalyticsInstanceIdAsync() function, and at least in Unity is shows up as a real and constant number. So I'm not sure if this is logging from other processes on my device.
I'm really confused on what I'm doing wrong. I've imported Firebase Analytics into my project with the google-services.json file that Firebase gave me, and my events seem to be firing correctly.
I also tried adding the SHA-1 number of my device to Firebase adnroid settings, using the command keytool -printcert -jarfile <package-name>.apk, which I don't think is necessary because I'm not using sign-in services or app invites. That doesn't seem to be having any effect, either.
Is there anything else I can try? Thanks so much!
OP here, I fixed this by basically starting from scratch-- deleting and then freshly importing my Firebase Library into Unity, deleting the Firebase project in the console and creating a new one, recreating/importing the GoogleService-Info.plist and google-services.json files. Then, using the same code, my android build would trigger 'Active users' in the Firebase Analytics console.
Good luck to anyone dealing with anything similar!
Related
I feel like I have tried every possible combination of ways to report a crash on the firebase crashlytics console for the android side of my react-native application.
I have followed the rnfirebase setup instructions and triple checked that everything is where it should be: https://rnfirebase.io/crashlytics/android-setup
I have read in several forums that the app needs to be run in 'release' mode for the crash to be reported and then the app must be closed and opened once again for the report to be sent, I have done this multiple times:
firstly i've tried:
./gradlew installRelease
secondly I tried a method recommended in a github issue forum:
./gradlew assembleRelease
adb install ./app/build/outputs/apk/release/app-release.apk
both methods ran on my emulator and I was able to use the crashlytics().crash() method to cause a crash, alas nothing appears in the console.
I have also added this into a firebase.json file in the root of my project like the docs explain:
{
"react-native": {
"crashlytics_debug_enabled": true
}
}
any help is greatly appreciated as I really don't know where the issue lies.
PS. I have registered my app with the FB console and enabled crashlytics
in firebase.json
{
"react-native": {
"crashlytics_disable_auto_disabler": true,
"crashlytics_debug_enabled": true
}
}
make sure that crashanalytics sdk is installed/initialised
follow: https://rnfirebase.io/crashlytics/android-setup
Wanted to get a crash report from firebase once the app gets crashed. Is it possible to get debug mode logs separate and production crash log separate in firebase crash?...because its not really clear when we get crash from production or debug test.
Also, firebase won't reflect crash report on the console after a crash happens.
What should I do to get up to date crash report?
Is there another way to get a crash report other than firebase?
I have updated the libraries which required for the firebase crashlytics.
and Followed tutorial - https://firebase.google.com/docs/crashlytics/get-started#android
Is it possible to get debug mode logs separate and production crash log separate in firebase crash?
It's common practice or perhaps even recommended that you create a separate project for testing and production. Download and place the google-services.json in your build flavor folder
~/app/src/release/google-services.json
~/app/src/debug/google-services.json
Even if you are only having a single Firebase project for test and production, you can filter your logs by the application id if you're setting up a project id suffix for the development build flavor:
~/app/build.gradle
buildTypes {
release {
}
debug {
applicationIdSuffix '.debug'
versionNameSuffix '-dbg'
}
}
Here you can see the different flavors being available in Crashlytics
Also, firebase won't reflect crash report on the console after a crash happens.
First time that you set up crashlytics it might take some time before the data shows up in the dashboard. But if it's been over 24 hours, it's likely that it's not properly set up. Try to explicitly trigger a crash to make sure that it works fine.
Button crashButton = new Button(this);
crashButton.setText("Crash!");
crashButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Crashlytics.getInstance().crash(); // Force a crash
}
});
Is there another way to get a crash report other than firebase?
Yes you can have more than one crash reporting tool if you have the need. You can perhaps create a wrapper class for crash reporting where you abstract the call to Crashlytics and you can add or change the underlying reporting platform there.
Upgrade SDK
After making the relevant settings for the migration to the new SDK, it is important to avoid the following error:
Attempting to send crash report at time of crash.
This can be caused by forcing a crash (without a button listen in my case) before FirebaseCrashlytics send the reports, that is, the Crashlytics Reports Endpoint upload is completed.
Test implementation
Enable Crashlytics debug logging
$ adb devices
$ adb shell setprop log.tag.FirebaseCrashlytics DEBUG
$ adb logcat -s FirebaseCrashlytics
1) First step: DONT force a crash and run the app. Observing how in the Crashlyticis logcat it is initialized correctly.
...
FirebaseCrashlytics: Update app request ID: 1d62cb...
FirebaseCrashlytics: Result was 204.
Crashlytics Reports Endpoint upload complete
2) Step Two: Force a crash (with a button or directly).
MainActivity.kt
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setupCrashlytics()
...
}
private fun setupCrashlytics() {
throw RuntimeException("Test crash") //TODO: Clean
}
Note: The only thing necessary to generate a report is this code in addition to the dependencies. Additionally you can login custom keys with FirebaseCrashlytics.getInstance().
Then run the app and check the following:
FirebaseCrashlytics: Crashlytics completed exception processing. Invoking default exception handler.
FirebaseCrashlytics: Attempting to send crash report at time of crash...
At this point the exception process is logged on the Firebase server but the reports have not yet been sent to the console, that is, the upload is incomplete.
3) Finally, we clean or comment on the crash crash
private fun setupCrashlytics() {
//throw RuntimeException("Test crash")
}
Run app and let's check:
Attempting to send 1 report(s)
FirebaseCrashlytics: Settings result was: 200
FirebaseCrashlytics: Adding single file 5EDA9D7....cls to report 5EDA9D7...
FirebaseCrashlytics: Sending report to: https://reports.crashlytics.com/spi/v1/platforms/android/apps/.../reports
FirebaseCrashlytics: Crashlytics Reports Endpoint upload complete: 5EDABB42 ...
This guarantees that the report reached the console.
GL
Firebase will not differentiate between debug and production versions logs/crashes in crashlytics if you have set auto collection of logs. You can use a logging library to only send logs and crashes if the app build.gradle has debug:fasle i.e. production.
You can look at the Timber logging library which has a great example of adding crash reporting. https://github.com/JakeWharton/timber
You have to disable the auto initialization of crashlytics in manifest to have control when crashes are sent to firebase
<meta-data
android:name="firebase_crashlytics_collection_enabled"
android:value="false" />
Then in your Application class's onCreate you check if BuildConfig.DEBUG is true you will not initialize crashlaytics so your debug logs and exceptions will not go to firebase, resulting in only production crashes.
For timber when you want to put logs and crashes to firebase you can use this Tree:
/**
* {#link Timber.Tree} using {#link Crashlytics} as crash reporting
*/
private static class CrashReportingTree extends Timber.Tree {
CrashReportingTree(Context context) {
CrashlyticsCore core = new CrashlyticsCore.Builder()
.disabled(BuildConfig.DEBUG)
.build();
Fabric.with(context, new Crashlytics.Builder().core(core).build());
}
#Override
protected void log(int priority, String tag, #NonNull String message, Throwable t) {
// don't report log to Crashlytics if priority is Verbose or Debug
if (priority == Log.VERBOSE || priority == Log.DEBUG) {
return;
}
Crashlytics.log(priority, tag, message);
if (t != null) {
if (priority == Log.ERROR) {
Crashlytics.logException(t);
}
}
}
}
For debug mode you should not send crashes to firebase as you can check the debug logs locally.
Please remove fabric.properties and remove all fabric related lines and files
I solve this issue thanks to AllwinJohnson solution in:
https://github.com/firebase/firebase-android-sdk/issues/1944
By Adding: FirebaseCrashlytics.getInstance()
in my onCreate in my Application class
The issue for me was the emulator itself. Fixing the date and time on the emulator did it for me as it was resulting in a CertificateNotYetValidException.
This will help if you moved from fabric SDK to Firebase Crashlytics.
Add the below line in your OnCreate() run the app and check your firebase crashlytics dashboard.
FirebaseCrashlytics.getInstance().sendUnsentReports();
In my case, I made the silly mistake of doing:
FirebaseCrashlytics.getInstance().setUserId(uid);
where uid was still null.
I've created an Android app and I am trying to set up Google Play services as I want to use the leader board etc.
I downloaded and imported the latest plugin "GooglePlayGamesPlugin-0.9.50 " and had no errors during the import.
I then go to assets/ play service resolver/android/force resolve and run that.
After running I end up with the following error:
Resolution failed
Failed to fetch the following dependencies:
com.google.games:gpgs-plugin-support:0.9.50
UnityEngine.Debug:LogError(Object)
Google.Logger:Log(String, LogLevel)
GooglePlayServices.PlayServicesResolver:Log(String, LogLevel)
GooglePlayServices.ResolverVer1_1:LogMissingDependenciesError(List`1)
GooglePlayServices.c_AnonStorey18:<>m_26(List`1)
GooglePlayServices.c_AnonStorey14:<>m_1F(Result)
GooglePlayServices.c_AnonStorey15:<>m_28()
GooglePlayServices.PlayServicesResolver:PumpUpdateQueue()
UnityEditor.EditorApplication:Internal_CallUpdateFunctions()
If I ignore the error and compile the app it works fine but does not connect to the Google service. I can publish and use the app without crashes etc but I can't log on to Google or view leader boards.
I am using: unity 2017.1.1f1 personal 64bit
Windows 10 64 bit
jdk1.8.0_162
You may refer with the workaround given in this thread.
Reimported Google Play Games Plugin (It will select the missing files by default).
Go to Assets menu => Play Services Resolver => Android Resolver => Force Resolve.
After resolving dependencies , Resolve Conflict window pops up. Click NO.
Build and Test your application
Add Debug.Log to check your authenticate status.
Social.localUser.Authenticate (success => {
if (success) {
Debug.Log ("SignIn successful");
} else {
Debug.Log ("SignIn failed");
}
});
Here are some additional references:
Resolution fails everytime trying to fetch gpgs-plugin-support
Gradle failed to fetch dependencies.
Hope this helps!
Navigate to your GooglePlayGamesPluginDependencies.xml file and make sure that the path mentioned for "com.google.games:gpgs-plugin-support:x.x.xx" exists and is valid. Then try Force Resolve again.
I have integrated my Firebase and Fabric projects since it's available few days ago.
I have such kind of fabric events tracking configured in my code:
Answers.getInstance().logCustom(new CustomEvent("Entity Click").putCustomAttribute("domain", entity.getDomain()).putCustomAttribute("entity", entity.entityId));
But in my Firebase console under Analytics -> Events and Analytics -> StreamView, I can't seem to see Fabric events get integrated over. All I can see is the normal generic Firebase events:
ad_click
ad_impression
app_clear_data
app_remove
app_update
first_open
os_update
screen_view
session_start
Did I misunderstand something?
UPDATE:
Portion of my build.gradle file:
classpath 'io.fabric.tools:gradle:1.24.4'
compile('com.crashlytics.sdk.android:crashlytics:2.7.1#aar') {
transitive = true;
}
#I did not use firebase-core
compile 'com.google.firebase:firebase-config:11.6.0'
compile 'com.google.firebase:firebase-ads:11.6.0'
compile 'com.google.firebase:firebase-messaging:11.6.0'
UPDATE 2:
In Fabric Console, Tools -> Firebase shows the linking in green:
UPDATE 3:
I'm using the new Firebase UI. Under Spark Plan, did not currently link to Big Query.
I did not really pay attention to my firebase events the past few days. But this morning I integrated my Firebase project over to Google Analytics at https://analytics.google.com in hope to gain some missing features like city/state level real-time location info. Turns out there's nothing new and it's the same info that I can find from Firebase Console. But when I check out the Events tab, I can now see my Fabric events. I then headed back to Firebase Console, and found my fabric events are showing now.
It could be the Analytics triggered the integration, or could have already populated in my Firebase prior to any of this. Either way, it's working for me now. :)
I face issue with get token from firebase (push notification)
Default FirebaseApp is not initialized in this process com.ready_apps.Nebka.Business. Make sure to call FirebaseApp.initializeApp(Context) first.
even I called FirebaseApp.InitializeApp(this); in many places
MyApplication (that extend Application) , in onCreate of Activity where I call FirebaseInstanceId.Instance?.Token;
Edit: This bug has been fixed in Xamarin.Firebase version 57.1104.0-beta1.
This error seems to be present in the newer versions of Firebase for Xamarin. I am also experiencing this error as of today, using the latest stable version 42.1021.1. (The error is also present in the latest beta build).
I found that a bug report has been filed for the issue here.
As mentioned in the bug report, deleting both the /obj and /bin folders in your Android project, and/or cleaning the project in Visual Studio should fix the problem temporarily until you update any resource that would change the Resource.Designer.cs file.
Downgrading to an older version of Firebase and Google Play Services is also possible before a permanent solution is available. I did not experience this error on Firebase and Google Play Services version 32.961.0, for example.
Just Clean the solution once and run the app again.
This bug is already reported to Xamarin.
https://bugzilla.xamarin.com/show_bug.cgi?id=56108
This solution is provided in their comment thread, it might get fixed in the newer release of xamarin NuGet package.
I didnt fix it but I find walkaround this issue in debug mode only
I called this method onCreate() in activit I need to request the token
FirebaseInstanceId.Instance?.Token
here is the method
private void ConfigureFireBase()
{
#if DEBUG
try
{
Task.Run(() =>
{
var instanceId = FirebaseInstanceId.Instance;
instanceId?.DeleteInstanceId();
//Log.Debug("TAG", "{0} {1}", instanceId?.Token?.ToString(), instanceId.GetToken(GetString(Resource.String.gcm_defaultSenderId), Firebase.Messaging.FirebaseMessaging.InstanceIdScope));
});
// For debug mode only - will accept the HTTPS certificate of Test/Dev server, as the HTTPS certificate is invalid /not trusted
ServicePointManager.ServerCertificateValidationCallback += (o, certificate, chain, errors) => true;
}catch (Exception e)
{
Log.Debug("TAG", e.Message);
}
#endif
}