UnsatisfiedLinkError: UnitySendMessage on Unity 5

Hey,

We released a new Android version of our game recently that is based on 5.0.1p2.

Since then we’re seeing many crashes with this message:

  1. Did anyone else experience these kind of errors after moving to Unity 5 ?
  2. Can this be related to libhoudini (e.g: ARM translator) ? we suspect some of these devices run the ARM translator to run an ARM binary on x86 cpu. Is this scenario still supported? I remember reading somewhere that it’s not working anymore in latest versions of Unity.

Our APK is built for ARMv7 only.

Do you have a local repro or a device fingerprint? If you are using the built in crash reporter (the one submitting to play console) there should be a device fingerprint in the error message.

I have reproduced the issue.

The problem is comprised of 2 parts:

  1. Our custom activity calls UnitySendMessage during onStart()
  2. The device has a Tegra 2 CPU (e.g: non-NEON) which is not supported anymore.

Loading the libunity.so fails in this case, and so the native function UnitySendMessage fails (it doesn’t exist).

That’s odd. You should be presented with an error message when creating the UnityPlayer. Meaning you should never reach the onStart() function. What does your custom activity look like?

Actually there are 2 levels of inheritence here, so that makes sense:

public AndroidNativeBridge : UnityPlayerActivity
public MainActivity : AndroidNativeBridge // our main activity

This is what happens in AndroidNativeBridge.onStart():

@Override
protected void onStart() {   
    try {   
        UnityPlayer.UnitySendMessage(ANDROID_APP_EVENT_LISTNER, "onStart", "");
        }
    } catch (NoClassDefFoundError ex) {
        Log.d("AndroidNative", "onStart: " + ex.getMessage());
    }
   
    super.onStart();
}

I guess this code is not relevant for first startup, since there’s no receiver object to take this message. But this call crashes anyway.

At what point are you displaying the error dialog? This method calls UnityPlayerActivity’s onStart. but it only does that after running its own logic…

Unless AndroidNativeBridge is doing something nasty you should get the error in OnCreate(). The check is in the ctor of UnityPlayer. It should present a dialog with an “OK” button and when the button is pressed UnityPlayer calls finish() on the Activity.

Do you have the onCreate code for MainActivity and AndroidNativeBridge?

Yes.

BTW - who creates UnityPlayer ? I suppose it’s created in UnityPlayerActvity’s onCreate method?

AndroidNativeBridge.onCreate:

@Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        inst = this;

    }

MainActivity.onCreate():

@Override
protected void onCreate(Bundle savedInstanceState) {
   
    // calls AndroidNativeBridge.onCreate
    super.onCreate(savedInstanceState);
   
    ImmersiveMode.enableImmersiveMode();

    // a bunch of other stuff ...   
}

Yes, it should be. Interesting enough you are not getting the Dialog. Could you try to remove the UnitySendMessage reference and see what kind of behaviour you get?

Removing the call from onStart() solved the issue and shows the message.

Do you think this should’ve been displayed during onCreate ?

That was the intention but I can’t say anyone actually confirmed that is the case. And reading about your situation my guess would be Dialog presentation is deferred until onStart is called - which sort of makes.

The dialog is shown using an instance of AlertDialog, specifically AlertDialog.show()

This method boils down to eventually post a message using sendShowMessage - http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.1.0_r1/android/app/Dialog.java#Dialog.sendShowMessage()

This sends a message to some Handler instance (http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.1.0_r1/android/os/Message.java#Message.sendToTarget())

Effectively, this code posts a message and waits for it to be handled, so, yes, it doesn’t happen immediately :slight_smile:

I believe this can be fixed somehow. Should i report an issue for this ?

Yes please :slight_smile:

1 Like

I reported this via email, seems like the bug reporting system is down or something… i did not receive any automated reply with the case number… will try again later.

I reported this as issue # 696580