How to debug: JNI DETECTED ERROR IN APPLICATION: use of invalid jobject
<p>I am working on a <code>Xamarin</code> Android project, and I get the following error (full log <a href="https://gist.github.com/sanandrea/7d9621c32ae565812e8a828c4a4c5ef7" rel="nofollow noreferrer">here</a>)</p>

<pre><code>11-07 08:28:09.067: A/art(7164): art/runtime/java_vm_ext.cc:410] JNI DETECTED ERROR IN APPLICATION: use of invalid jobject 0xd4fd90e0
11-07 08:28:09.067: A/art(7164): art/runtime/java_vm_ext.cc:410] "Thread-1973" prio=10 tid=26 Runnable
11-07 08:28:09.067: A/art(7164): art/runtime/java_vm_ext.cc:410]   | group="main" sCount=0 dsCount=0 obj=0x137270a0 self=0xc89d4900
11-07 08:28:09.067: A/art(7164): art/runtime/java_vm_ext.cc:410]   | sysTid=9034 nice=-11 cgrp=default sched=0/0 handle=0xd4b3a930
11-07 08:28:09.067: A/art(7164): art/runtime/java_vm_ext.cc:410]   | state=R schedstat=( 310795035 15833156 94 ) utm=24 stm=7 core=5 HZ=100
11-07 08:28:09.067: A/art(7164): art/runtime/java_vm_ext.cc:410]   | stack=0xd4a3c000-0xd4a3e000 stackSize=1022KB
11-07 08:28:09.067: A/art(7164): art/runtime/java_vm_ext.cc:41n0]   | held mutexes= "mutator lock"(shared held)
</code></pre>

<p>when try to play a movie (custom third party ExoPlayer wrapper library) while in airplane mode. I am not seeking help to find the bug with only this info, but only a way to debug app. When crash appears the debugger is disconnected. </p>

<p>Also I have seen this thread: <a href="https://bugzilla.xamarin.com/show_bug.cgi?id=45281" rel="nofollow noreferrer">https://bugzilla.xamarin.com/show_bug.cgi?id=45281</a>
on Xamarin bugzilla, but when I enable GC logs with the following:</p>

<pre><code>$ adb shell setprop debug.mono.log gref,gc
</code></pre>

<p>the app does not crash!!!</p>

<p>I am testing on device <code>Samsung SM-G930F</code> aka <code>Samsung S7</code> and using <code>API level 23</code>. The error appears also on other devices.</p>

<p>My build setup:</p>

<pre><code>Xamarin Studio Community
Version 6.1.1 (build 15)
Installation UUID: b3096ed4-0118-4e0d-87f4-a1fe79ffc301
Runtime:
    Mono 4.6.1 (mono-4.6.0-branch-c8sr0/ef43c15) (64-bit)
    GTK+ 2.24.23 (Raleigh theme)

    Package version: 406010005

NuGet
Version: 3.4.3.0

Xamarin.Profiler
Not Installed

Apple Developer Tools
Xcode 8.1 (11544)
Build 8B62

Xamarin.Mac
Version: 2.10.0.105 (Xamarin Studio Community)

Xamarin.iOS
Version: 10.0.1.10 (Xamarin Studio Community)
Hash: ad1cd42
Branch: cycle8-sr0-xi
Build date: 2016-10-03 15:18:44-0400

Xamarin.Android
Version: 7.0.1.3 (Xamarin Studio Community)
Android SDK: /Users/andi/Library/Android/sdk
    Supported Android versions:
        5.0 (API level 21)
        6.0 (API level 23)
        7.0 (API level 24)

SDK Tools Version: 25.2.2
SDK Platform Tools Version: 24.0.3
SDK Build Tools Version: 23.0.1

Java SDK: /usr
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Xamarin Android Player
Version: 0.6.5
Location: /Applications/Xamarin Android Player.app

Build Information
Release ID: 601010015
Git revision: fa52f02641726146e2589ed86ec4097fbe101888
Build date: 2016-09-22 08:03:02-04
Xamarin addins: 75d65712af93d54dc39ae4c42b21dfa574859fd6
Build lane: monodevelop-lion-cycle8-sr0

Operating System
Mac OS X 10.12.1
Darwin Pentagon.local 16.1.0 Darwin Kernel Version 16.1.0
    Thu Oct 13 21:26:57 PDT 2016
    root:xnu-3789.21.3~60/RELEASE_X86_64 x86_64
</code></pre>

<p><strong>EDIT:</strong></p>

<p>With gref enabled log (no crash): <a href="https://gist.github.com/sanandrea/b9a837b8c885ac037c4f4bc6e8030d10" rel="nofollow noreferrer">https://gist.github.com/sanandrea/b9a837b8c885ac037c4f4bc6e8030d10</a></p>

<p>Without gref enabled (crash): <a href="https://gist.github.com/sanandrea/d2c5c895b4bc15f45381421c9c21b859" rel="nofollow noreferrer">https://gist.github.com/sanandrea/d2c5c895b4bc15f45381421c9c21b859</a></p>

<p><strong>EDIT 2</strong>
This can be tagged as #HeisenBug</p>