Xamarin.Android.Crashlytics 2.9.4.1 - CrashlyticsCore 上的 NoClassDefFoundError

Xamarin.Android.Crashlytics 2.9.4.1 - NoClassDefFoundError on CrashlyticsCore

我正在尝试构建 Xamarin.Forms 应用程序的 Android 发布版本,但输出 apk 在 Crashlytics 初始化时不断崩溃。 好像找不到 com.crashlytics.android.core.CrashlyticsCore class.

与调试版本的主要(也可能是唯一)区别是启用了 Multidex。

我已经尝试通过添加这两行来解决问题:

com/crashlytics/android/Crashlytics.class
com/crashlytics/android/core/CrashlyticsCore.class

生成操作设置为 MultiDexMainDexListmultidex.keep 文件,但结果没有改变。

我正在 MainAcvitity OnCreate 方法中初始化 Crashlytics,如下所示:

Fabric.Fabric.With(this, new Crashlytics.Crashlytics());
Crashlytics.Crashlytics.HandleManagedExceptions();

堆栈跟踪:

[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] Java.Lang.NoClassDefFoundError: com.crashlytics.android.core.CrashlyticsCore
[MonoDroid]   at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00089] in <34f201f6cca4421387fe7278a4375940>:0 
[MonoDroid]   at Java.Interop.JniPeerMembers+JniInstanceMethods.FinishCreateInstance (System.String constructorSignature, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0004f] in <34f201f6cca4421387fe7278a4375940>:0 
[MonoDroid]   at Crashlytics.Crashlytics..ctor () [0x00054] in <114e650c181c4522b75b2d021c6a77a9>:0 
[MonoDroid]   at FollowFun.Droid.MainActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00026] in <6c170c583d7f4be9a657f0283b3a6d04>:0 
[MonoDroid]   at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in <16a97b0d1e0a45cc9db76f74432e8848>:0 
[MonoDroid]   at (wrapper dynamic-method) System.Object.16(intptr,intptr,intptr)
[MonoDroid]   --- End of managed Java.Lang.NoClassDefFoundError stack trace ---
[MonoDroid] java.lang.NoClassDefFoundError: com.crashlytics.android.core.CrashlyticsCore
[MonoDroid]     at com.crashlytics.android.Crashlytics.<init>(Crashlytics.java:29)
[MonoDroid]     at md509b0a614f9e78774f77a51d8579dfa9f.MainActivity.n_onCreate(Native Method)
[MonoDroid]     at md509b0a614f9e78774f77a51d8579dfa9f.MainActivity.onCreate(MainActivity.java:38)
[MonoDroid]     at android.app.Activity.performCreate(Activity.java:5231)
[MonoDroid]     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
[MonoDroid]     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
[MonoDroid]     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
[MonoDroid]     at android.app.ActivityThread.access0(ActivityThread.java:135)
[MonoDroid]     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
[MonoDroid]     at android.os.Handler.dispatchMessage(Handler.java:102)
[MonoDroid]     at android.os.Looper.loop(Looper.java:136)
[MonoDroid]     at android.app.ActivityThread.main(ActivityThread.java:5001)
[MonoDroid]     at java.lang.reflect.Method.invokeNative(Native Method)
[MonoDroid]     at java.lang.reflect.Method.invoke(Method.java:515)
[MonoDroid]     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
[MonoDroid]     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
[MonoDroid]     at dalvik.system.NativeStart.main(Native Method)
[AndroidRuntime] Shutting down VM
[AndroidRuntime] FATAL EXCEPTION: main
[AndroidRuntime] Process: my.app, PID: 1441
[AndroidRuntime] java.lang.NoClassDefFoundError: com.crashlytics.android.core.CrashlyticsCore
[AndroidRuntime]    at com.crashlytics.android.Crashlytics.<init>(Crashlytics.java:29)
[AndroidRuntime]    at md509b0a614f9e78774f77a51d8579dfa9f.MainActivity.n_onCreate(Native Method)
[AndroidRuntime]    at md509b0a614f9e78774f77a51d8579dfa9f.MainActivity.onCreate(MainActivity.java:38)
[AndroidRuntime]    at android.app.Activity.performCreate(Activity.java:5231)
[AndroidRuntime]    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
[AndroidRuntime]    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
[AndroidRuntime]    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
[AndroidRuntime]    at android.app.ActivityThread.access0(ActivityThread.java:135)
[AndroidRuntime]    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
[AndroidRuntime]    at android.os.Handler.dispatchMessage(Handler.java:102)
[AndroidRuntime]    at android.os.Looper.loop(Looper.java:136)
[AndroidRuntime]    at android.app.ActivityThread.main(ActivityThread.java:5001)
[AndroidRuntime]    at java.lang.reflect.Method.invokeNative(Native Method)
[AndroidRuntime]    at java.lang.reflect.Method.invoke(Method.java:515)
[AndroidRuntime]    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
[AndroidRuntime]    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
[AndroidRuntime]    at dalvik.system.NativeStart.main(Native Method)
[Process] Sending signal. PID: 1441 SIG: 9

Visual Studio 对于 Mac 版本:

Visual Studio Community 2017 for Mac
Version 7.6.7 (build 49)
Installation UUID: [...]
Runtime:
    Mono 5.12.0.301 (2018-02/4fe3280bba1) (64-bit)
    GTK+ 2.24.23 (Raleigh theme)
    Xamarin.Mac 4.4.1.178 (master / eeaeb7e6)

    Package version: 512000301

Xamarin.Android版本:

Xamarin.Android
Version: 9.0.0.20 (Visual Studio Community)
Android SDK: /Applications/Utilities/android-sdk
    Supported Android versions:
        4.0.3 (API level 15)
        4.1   (API level 16)
        4.4   (API level 19)
        5.0   (API level 21)
        5.1   (API level 22)
        6.0   (API level 23)
        7.0   (API level 24)
        7.1   (API level 25)
        8.1   (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 28.0.1
SDK Build Tools Version: 28.0.3

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

我已经通过 NuGet 在我的项目中安装了这些包: - Xamarin.Android.Crashlytics 2.9.4.1 - Xamarin.Android.Crashlytics.Answers 1.4.2 - Xamarin.Android.Crashlytics.Beta 1.2.9 - Xamarin.Firebase.Core 60.1142.1

我已经尝试在 Mac OS 和 Windows 10 上构建项目,结果是同样的崩溃。

我觉得我已经尝试了所有方法,有人有什么建议可以帮助我解决这个问题吗?

不幸的是,这似乎是 Xamarin.Android.Crashlytics NuGet 包依赖项的问题。

您需要手动将 Xamarin.Android.Crashlytics.Core 添加到项目中。

参见this GitHub issue