Android NDK: UnsatisfiedLinkError when calling libfmod.so and using Proguard

Hi’re,

I’m getting an UnsatisfiedLinkError exception when calling System.loadLibrary("fmod"); and using Proguard. It works fine without Proguard on.

In both cases, the libfmod.so exists in the lib/arm directory of the APK.

I’m using Android Studio with gradle. I activate Proguard with the minifyEnabled property set to true.

Do you guys have any idea of what’s going on?

Thanks!

The code in Main.java:

static {
    System.loadLibrary("fmod");
    System.loadLibrary("fmodstudio");
    System.loadLibrary("Main");
}

The log:

E/AndroidRuntime: FATAL EXCEPTION: main
E/AndroidRuntime: Process: com.<snip>, PID: 20003
E/AndroidRuntime: java.lang.UnsatisfiedLinkError: JNI_ERR returned from JNI_OnLoad in "/data/app/com.<snip>/lib/arm/libfmod.so"
E/AndroidRuntime:     at java.lang.Runtime.loadLibrary(Runtime.java:371)
E/AndroidRuntime:     at java.lang.System.loadLibrary(System.java:988)
E/AndroidRuntime:     at com.<snip>.<clinit>`

FMOD native code will call out to the fmod.jar, we verify this is possible in JNI_OnLoad. When you obfuscate the fmod.jar there is no way for the native code to find the necessary methods so it returns a JNI_ERR.

I think you just need to exclude the fmod.jar from ProGuard, a quick Google reveals this stack overflow page that discusses how to do it.

1 Like

Thanks Mathew! I had to change my FMOD proguard configuration:
from -keepclassmembers class org.fmod.** { *; }
to -keep class org.fmod.** { *; }

1 Like