Native Method Exception on launch after upgrading past 5.3.4

Some background:

Our game has a LOT of SDKs, so we have to make our builds externally with Android Studio. Since upgrading to 5.3.6 (also confirmed issue on 5.4.0), the game crashes on startup with the following error:

08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxxx E/dalvikvm: ERROR: couldn't find native method
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxxx E/dalvikvm: Requested: Lcom/unity3d/player/UnityPlayer;.nativeUnitySendMessage:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxxx W/dalvikvm: JNI WARNING: JNI function FatalError called with exception pending
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxxx W/dalvikvm:              in Lcom/unity3d/player/NativeLoader;.load:(Ljava/lang/String;)Z (FatalError)
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxxx W/dalvikvm: Pending exception is:
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxxx I/dalvikvm: java.lang.NoSuchMethodError: no static or non-static method "Lcom/unity3d/player/UnityPlayer;.nativeUnitySendMessage(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxxx I/dalvikvm:     at com.unity3d.player.NativeLoader.load(Native Method)
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxxx I/dalvikvm:     at com.unity3d.player.UnityPlayer.a((null):-1)
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxxx I/dalvikvm:     at com.unity3d.player.UnityPlayer.<init>((null):-1)
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxxx I/dalvikvm:     at com.localytics.android.unity.LocalyticsUnityPlayerActivity.onCreate(LocalyticsUnityPlayerActivity.java:33)
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxxx I/dalvikvm:     at android.app.Activity.performCreate(Activity.java:5275)

(I’ve included what I think is the relevant portion of the stacktrace and log, I can include more if needed). The exception appears to happen immediately in the UnityPlayerActivity base class, so I feel like something is fundamentally broken with the build.

The only clue I’ve been able to dig up is this bugfix that occurred between those versions, but I’m not sure why it would cause the issue rather than fixing it: Unity Issue Tracker - [Andorid/Plugins] java.lang.NoSuchMethodError when invoking public static method with AndroidJavaObject

For now we’re going to revert to doing builds with 5.3.4, but if anyone has ideas it would be appreciated.

I don’t think that bugfix is related.

DISCLAIMER: long read ahead with a bunch of non-conventional tools used (listed through my answer).
A few things that perhaps could help:

  • Convert .apk to .zip and unzip. Do you have all the required native (.so) libs inside? (libmono, libmain, libunity) ?
  • Is your build a “FAT” .apk ? (e.g: contains both ARM and x86 libraries) ? if not, are you trying to run a build that matches the target architecture ?
  • Did you update anything else at the same time? Android Studio? Android SDK ?

From the looks of it, you are using Localytics which provides its own activity. It is responsible for instantiating the UnityPlayer class (their SDK is open source). When UnityPlayer is created, it loads libmain.so and later on will call com.unity3d.player.NativeLoader.load(Native Method) which is a native method (you can decompile Unity’s classes.jar online to see what it’s doing inside).

This native method call somehow results in an exception. We can try to peek inside using objdump from the Android NDK.

I used the following command BTW:

I couldn’t find any exact trace for the code that actually tries to use nativeUnitySendMessage, but this native function is implemented in libunity.so. I suspect that libmain (and specifically, the load function) is responsible for loading this .so (or in fact, all other .so libraries in the APK), but somehow this fails so this function is not found.

Let me know if you peeked inside the .apk and found anything useful :slight_smile:

Thanks for taking the time to look into this. In answer to your questions, I looked inside the APK and there are folders for both platforms with all of the SO files included. I did not update anything else as far as I know; in fact, I have both of the relevant Unity versions side by side and did builds with each to compare. They seem the same, except one works (5.3.4) and the others have this error (5.3.6 and 5.4.0).

I should probably note before going further that we’ve never been able to build directly from the Android Studio project Unity exports. What we ended up doing a while ago was taking that project and tweaking it in numerous ways until it finally built, then stripped it down to the essentials and checked the skeleton project into our source control. We then added a post-build script to Unity that “injects” the relevant game content from the exported project into the skeleton project, and then build that from Android Studio.

So to put it lightly, our Android build process is an abomination.

Here is the full stack trace in case that provides more information. You can see that libunity.so is mentioned in there at some point, though I’m not sure of the context. I’m assuming the UnitySendMessage method is pretty integral and thus something basic isn’t being loaded. It would seem that something under the hood with Unity changed between those versions.

08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxx E/dalvikvm: ERROR: couldn't find native method
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxx E/dalvikvm: Requested: Lcom/unity3d/player/UnityPlayer;.nativeUnitySendMessage:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxx W/dalvikvm: JNI WARNING: JNI function FatalError called with exception pending
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxx W/dalvikvm:              in Lcom/unity3d/player/NativeLoader;.load:(Ljava/lang/String;)Z (FatalError)
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxx W/dalvikvm: Pending exception is:
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxx I/dalvikvm: java.lang.NoSuchMethodError: no static or non-static method "Lcom/unity3d/player/UnityPlayer;.nativeUnitySendMessage(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at com.unity3d.player.NativeLoader.load(Native Method)
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at com.unity3d.player.UnityPlayer.a((null):-1)
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at com.unity3d.player.UnityPlayer.<init>((null):-1)
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at com.localytics.android.unity.LocalyticsUnityPlayerActivity.onCreate(LocalyticsUnityPlayerActivity.java:33)
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at android.app.Activity.performCreate(Activity.java:5275)
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2164)
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250)
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at android.app.ActivityThread.access$800(ActivityThread.java:139)
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at android.os.Handler.dispatchMessage(Handler.java:102)
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at android.os.Looper.loop(Looper.java:136)
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at android.app.ActivityThread.main(ActivityThread.java:5105)
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at java.lang.reflect.Method.invokeNative(Native Method)
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at java.lang.reflect.Method.invoke(Method.java:515)
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at dalvik.system.NativeStart.main(Native Method)
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxx I/dalvikvm: "main" prio=5 tid=1 NATIVE
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:   | group="main" sCount=0 dsCount=0 obj=0x418a3f48 self=0x41825010
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:   | sysTid=10378 nice=0 sched=0/0 cgrp=apps handle=1074458964
08-02 11:05:33.618 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:   | state=R schedstat=( 0 0 0 ) utm=11 stm=8 core=2
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:   #00  pc 0000132e  /system/lib/libcorkscrew.so (unwind_backtrace_thread+29)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:   #01  pc 00063866  /system/lib/libdvm.so (dvmDumpNativeStack(DebugOutputTarget const*, int)+33)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:   #02  pc 00057844  /system/lib/libdvm.so (dvmDumpThreadEx(DebugOutputTarget const*, Thread*, bool)+395)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:   #03  pc 000578b2  /system/lib/libdvm.so (dvmDumpThread(Thread*, bool)+25)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:   #04  pc 0003b8cc  /system/lib/libdvm.so
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:   #05  pc 000443c2  /system/lib/libdvm.so
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:   #06  pc 006a63f0  /data/app-lib/com.xxxxxx.xxxxx-2/libunity.so (JNI_OnLoad+184)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:   #07  pc 00002ab8  /data/app-lib/com.xxxxxx.xxxxx-2/libmain.so
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:   #08  pc 00002838  /data/app-lib/com.xxxxxx.xxxxx-2/libmain.so
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:   #09  pc 000204cc  /system/lib/libdvm.so (dvmPlatformInvoke+112)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:   #10  pc 000512ae  /system/lib/libdvm.so (dvmCallJNIMethod(unsigned int const*, JValue*, Method const*, Thread*)+397)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:   #11  pc 00029960  /system/lib/libdvm.so
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:   #12  pc 00030ec8  /system/lib/libdvm.so (dvmMterpStd(Thread*)+76)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:   #13  pc 0002e560  /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+184)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:   #14  pc 00063a78  /system/lib/libdvm.so (dvmInvokeMethod(Object*, Method const*, ArrayObject*, ArrayObject*, ClassObject*, bool)+391)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:   #15  pc 0006b942  /system/lib/libdvm.so
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:   #16  pc 00029960  /system/lib/libdvm.so
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:   #17  pc 00030ec8  /system/lib/libdvm.so (dvmMterpStd(Thread*)+76)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:   #18  pc 0002e560  /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+184)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:   #19  pc 00063794  /system/lib/libdvm.so (dvmCallMethodV(Thread*, Method const*, Object*, bool, JValue*, std::__va_list)+335)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:   #20  pc 0004ce96  /system/lib/libdvm.so
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:   #21  pc 0004decc  /system/lib/libandroid_runtime.so
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:   #22  pc 0004ec26  /system/lib/libandroid_runtime.so (android::AndroidRuntime::start(char const*, char const*)+353)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:   #23  pc 0000109a  /system/bin/app_process
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:   #24  pc 0000e558  /system/lib/libc.so (__libc_init+47)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at com.unity3d.player.NativeLoader.load(Native Method)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at com.unity3d.player.UnityPlayer.a((null):-1)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at com.unity3d.player.UnityPlayer.<init>((null):-1)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at com.localytics.android.unity.LocalyticsUnityPlayerActivity.onCreate(LocalyticsUnityPlayerActivity.java:33)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at android.app.Activity.performCreate(Activity.java:5275)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2164)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at android.app.ActivityThread.access$800(ActivityThread.java:139)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at android.os.Handler.dispatchMessage(Handler.java:102)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at android.os.Looper.loop(Looper.java:136)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at android.app.ActivityThread.main(ActivityThread.java:5105)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at java.lang.reflect.Method.invokeNative(Native Method)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at java.lang.reflect.Method.invoke(Method.java:515)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx I/dalvikvm:     at dalvik.system.NativeStart.main(Native Method)
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx E/dalvikvm: VM aborting
08-02 11:05:33.628 10378-10378/com.xxxxxx.xxxxx A/libc: Fatal signal 6 (SIGABRT) at 0x0000288a (code=-6), thread 10378 (susa.xxxxxx)

With the knowledge of your project skeleton “abomination” , i would suspect something may be related to that.

Is there anything that is Unity-version specific in that skeleton? which Unity version did you use when you created the skeleton? what is contained in it ?

Also, looking at the error again, it looks like there was a failure calling a JNI (native) method due to a pending exception. That means that something else previously failed. Did you see any error message prior to this one ?

You can try to enable JNI extended checking (نصائح من "مبادرة أخبار Google"  |  Android NDK  |  Android Developers) by calling

and then launching the game.

Also, another interesting test would be to test a development build, is possible. Maybe more information will be present there.

In any case - it’s hard to tell what’s exactly wrong. as you said - “UnitySendMessage method is pretty integral and thus something basic isn’t being loaded”.

Ugh, now I feel stupid.

The skeleton project has a libs/ folder that has been specially curated and is not updated each time Unity does a build. I’m aware this is not ideal but it was necessary to get the project to build. Thus if we update any of the SDK jars in the Unity project I have to manually move them over to the skeleton project.

Well it turns out one of those libs is unity-classes.jar, which as you pointed out is quite specific to the version of Unity building the project. Switching that out with the one for 5.4.0 results in a successful launch.

So I think we’re good, for now. Thank you so much for your help. There will no doubt be more issues down the line but this one was really puzzling me, though in retrospect it should have been pretty obvious (on my end).

1 Like

No prob :slight_smile: