Crash when distributing app, KSemenenko.GoogleAnalytics related

KeithBoyntonKeithBoynton GBMember ✭✭
edited July 5 in Xamarin.Mac

I've implemented KSemenenko's GoogleAnalytics package into a Windows, Xamarin.iOS and Xamarin.Mac version of my app and everything is working really well in Debug within Visual Studio. Things are showing up in Google Analytics from all versions of the app.

However when I come to package up and distribute, it crashes on the distributed version with the following stack trace:

Crashed Thread:        0  tid_307  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Segmentation fault: 11
Termination Reason:    Namespace SIGNAL, Code 0xb
Terminating Process:   exc handler [497]

Thread 0 Crashed:: tid_307  Dispatch queue: com.apple.main-thread
0   com.xxxxx.xxxxxxxxxxx           0x000000010d7b005d eglib_log_adapter + 13 (mono-logger.c:404)
1   com.xxxxx.xxxxxxxxxxx           0x000000010d7ca26e monoeg_g_logv_nofree + 190 (goutput.c:150)
2   com.xxxxx.xxxxxxxxxxx           0x000000010d7ca3ef monoeg_assertion_message + 143 (goutput.c:184)
3   com.xxxxx.xxxxxxxxxxx           0x000000010d5a8a69 mono_jit_thread_attach + 169
4   com.xxxxx.xxxxxxxxxxx           0x000000010d4bd5a0 xamarin_switch_gchandle + 144 (runtime.m:1853)
5   com.xxxxx.xxxxxxxxxxx           0x000000010d4c0217 xamarin_release_trampoline + 103 (trampolines.m:474)
6   libobjc.A.dylib                 0x0000000119a3711a (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 710
7   com.xxxxx.xxxxxxxxxxx           0x000000010d4c79c2 xamarin_main + 1234 (launcher.m:674)
8   com.xxxxx.xxxxxxxxxxx           0x000000010d4c8834 main + 36 (launcher.m:679)
9   libdyld.dylib                   0x000000011a4ec3d5 start + 1

I've wrapped it in a static class...

using Plugin.GoogleAnalytics;

namespace Core.Analytics
{
 public static class AppClient
    {
        public static void Initialise()
        {
            GoogleAnalytics.Current.Config.TrackingId = "XXX";
            GoogleAnalytics.Current.Config.AppId = "XXX";
            GoogleAnalytics.Current.Config.AppName = "XXX";
            GoogleAnalytics.Current.Config.AppVersion = "XXX";
            GoogleAnalytics.Current.Config.AppInstallerId = "XXX";
            GoogleAnalytics.Current.Config.StartMessage = "Startup";
            GoogleAnalytics.Current.Tracker.DataSource = "app";

#if __MACOS__
            GoogleAnalytics.Current.Tracker.UserAgentOverride = $"Mozilla/5.0 (Mac OS {Environment.OSVersion.Version.Major}.{Environment.OSVersion.Version.Minor}; Trident/7.0; rv:11.0) like Geko";
#endif

            GoogleAnalytics.Current.InitTracker();
        }
    }
}

And I call it from my app logic....

// Set up analytics
LogWriter.Info ("Setting up analytics");
Analytics.AppClient.Initialise();
LogWriter.Info ("Done");

The Analytics.AppClient.Initialise(); line is where it crashes. The "Setting up analytics" logging gets written but not the "Done" line.

The only thing I can think that may be happening is that something is being linked away during build, but it does run just fine in VS with the Distribution target and it's set to Don't Link!

Posts

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai
    5   com.xxxxx.xxxxxxxxxxx           0x000000010d4c0217 xamarin_release_trampoline + 103 (trampolines.m:474)
    6   libobjc.A.dylib                 0x0000000119a3711a (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 710
    

    This makes it seem like something is getting collected prematurely or is having lifetime issues.

    Consider running your application under Apple's Instruments to figure out who's object is having issues.

  • KeithBoyntonKeithBoynton GBMember ✭✭

    Thanks so much @ChrisHamons for your suggestion. Actually with the help of @DennisWelu we've discovered that it's because the package is trying to write internal cache files directly into the package I'm literally just about to test it now...

    In case anyone else bumps into this here's the history and the workaround...

    https://github.com/KSemenenko/GoogleAnalyticsForXamarinForms/issues/37

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    Yes, writing inside your own package is a crazy thing for macOS applications to do.

    There are plenty of better locations, and this will absolutely crash you.

Sign In or Register to comment.