1

I've started to use Azure Mobile Center for a Xamarin.Forms app , for the Android piece.

I've added the required Mobile Center SDK calls, but I still cannot see anything in Analytics. As note, I can build and distribute the app properly.

This is how the App() constructor in App.xams.cs looks like :

public App()
{            
     InitializeComponent();            
     MobileCenter.Start(typeof(Analytics), typeof(Crashes));
     MobileCenter.LogLevel = LogLevel.Verbose;
}

and I've also added the configure call in the OnCreate event in MainActivity.cs

protected override void OnCreate(Bundle bundle)
{
     TabLayoutResource = Resource.Layout.tabs;
     ToolbarResource = Resource.Layout.toolbar;

     base.OnCreate(bundle);

     global::Xamarin.Forms.Forms.Init(this, bundle);
     MobileCenter.Configure("my_app_id");
     LoadApplication(new App(new AndroidInitializer()));
}

After a few tests, it seems that Prism affects in a way the MobileCenter class. The App() constructor is not being called, so I've added this to the existing constructor :

public App(IPlatformInitializer initializer = null) : base(initializer) {
        MobileCenter.Start(typeof(Analytics), typeof(Crashes));
    }

but I get an "System.NullReferenceException: Object reference not set to an instance of an object." It seems Crashes and Analytics are not initialized properly. The MobileCenter is a static class, so maybe this affects its initialization.

Any help is appreciated. Thank you,

Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123
Marius B.
  • 478
  • 6
  • 18
  • 1
    Are you using any other crash reporting tools in the same app, such as Hockeyapp, Xamarin.Insights, Crashalytics, etc? – Brandon Minnick Jan 20 '17 at 18:55
  • 1
    Hi to avoid missing some debug logs, you should move `MobileCenter.LogLevel = LogLevel.Verbose` before the call to `Configure`. Then either use `adb bugreport` to create a debug file that will contain all the logs or manually extract all logs with tag starting with `MobileCenter` so that we can investigate it. – Guillaume Perrot Jan 20 '17 at 19:03
  • I do not use other crashing report tools. I'll move the LogLevel call and get back to you. Thanks all for your input. – Marius B. Jan 21 '17 at 07:50
  • I see you already have opened an intercom ticket, you can upload logs there. – Guillaume Perrot Jan 23 '17 at 21:25

3 Answers3

1

Move the call into the OnInitialized method.

  • Thanks Brian! It works. I've put "MobileCenter.Start(typeof(Analytics), typeof(Crashes));" after the InitializeComponent call on the OnInitialized method. Thanks again, appreciate it. – Marius B. Jan 25 '17 at 15:33
  • Marius, did you resolve your problem? I've the same problem. My app is crashes every day when it open – Damir Beylkhanov Apr 23 '17 at 19:31
0

I'm using in the app Prism to implement MVVM. I had a hunch that this might affects things; I've created a new project, without using Prism, and voila...I can see Analytics...finally!

The issue is in what way Prism affects the MobileCenter. I've updated the original question.

Marius B.
  • 478
  • 6
  • 18
  • 1
    If you get a null reference exception, it happens that sometimes one of the nuget packages is not installed correctly in the android project. I saw a situation where the assembly reference between used in the android project was the portable DLL and not the mono android DLL. The solution in that case is to clear package cache and uninstall/reinstall the nuget packages in the Android project. – Guillaume Perrot Jan 23 '17 at 21:28
  • Thanks, I'll give it a go. – Marius B. Jan 24 '17 at 08:23
  • I had a same issue like @GuillaumePerrot, solution for this issue can be to clean your solution and delete obj bin folders and than rebuild your solution – Almir Vuk Feb 16 '18 at 13:22
0

In my case, it was because I had only installed the Nuget packages(Analytics & Crashes) for the shared project. Installing it for the iOS project as well fixed it.

Isaack Rasmussen
  • 457
  • 4
  • 11