Search code examples
android-ndkaar

UnsatisfiedLinkError couldn't find "libnative-lib.so" with libnative-lib.so visible in aar file


So I built an Android aar library which contains a native library (libnative-lib.so). Due to backward compatibility consideration, it's only built for armeabi and x86 architectures.

Now, I place the aar file and use it in my "client" app, I can clearly see the libnative-lib.so are under the aar's jni/armeabi and jni/x86 folders.

But the app crashes with this message:

java.lang.UnsatisfiedLinkError: ...
nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]] couldn't find "libnative-lib.so"

This looks like the client app isn't able to find the nativelib from aar. Any suggestions?


Solution

  • Actually in my case, due to the mentioned backward compatibility consideration, I need to put this in my library's build.gradle:

    packagingOptions {
        exclude 'lib/armeabi-v7a/libnative-lib.so'
        exclude 'lib/x86_64/libnative-lib.so'
    }
    

    to guard the build away from the unwanted architectures.