title: Firebase Crashlytics and NDK Native Crashes
body: <p>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.</p>
  
  <p>To have native crashes working, I started by just adding a dependency on the CrashlyticsNDK .aar (<em>com.crashlytics.sdk.android.crashlytics-ndk-2.1.0</em>), but no luck. Searching on the internet, I found that I might need <a href="https://stackoverflow.com/questions/50986823/firebase-crashlytics-does-not-support-ndk">initialize Fabric myself</a>. So I added the meta-data line in the manifest to disable automatic initialization, and added the following code in our <em>Activity.onCreate()</em>:</p>
  
  <p><code>Fabric.with(this, new Crashlytics(), new CrashlyticsNdk());</code></p>
  
  <p>I see in the logs that auto-initialization is skipped. Still, no fatal crash being logged in the console. </p>
  
  <p>I decompiled all those .aar files to try to understand what's going on. I found that whenever we disable auto-initialization, <em>io.fabric.sdk.android.Fabric.java</em> goes through a whitelisting logic that removes the CrashlyticsNdk kit from the list! It prints the following message in the logs:</p>
  
  <pre><code>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.
  </code></pre>
  
  <p><br/>
  Then, I tried to hack the Fabric initialization by pretending the data collection is on during initialization only, as follow:</p>
  
  <pre><code>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);
  </code></pre>
  
  <p><br/>
  Now, I can see some interesting log lines:</p>
  
  <pre><code>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
  </code></pre>
  
  <p><br/>
  So, when I crash the app and run it again, I get the log line below:</p>
  
  <pre><code>08-01 22:45:39.489: W/CrashlyticsCore(24353): Received null settings, skipping report submission!
  </code></pre>
  
  <p><br/>
  I have the impression the crash was handled correctly, but Crashlytics could not upload the crash data because of invalid/null settings.</p>
  
  <p>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. </p>
  
  <p>Thanks in advance, and sorry if I was too verbose. Just wanted to show the whole context.</p>