.SO file not packed with APK file
I m trying to integrate the zstd native C gradle dependency in my android project. The dependency is as below :
dependencies {
implementation "com.github.luben:zstd-jni:1.5.5-4@aar"
}
My android app is a multi module architecture. I have a main module and then there are sub modules like network, image loading, analytics etc added as sdk(gradle dependency) in the main module build.gradle file. I have added above zstd dependency in my network module and it works perfectly. The zstd .so files are loaded in the lib folder for different CPU architectures when I create the apk of network module and compression/decompression functionality also works well. Now when I add network module artifact in my main module build.gradle then the zstd .so files are not loaded in the lib folder in the main module apk. I have observed that when I add zstd dependency directly in main module build.gradle then .so files gets loaded. But when added via network module .so files doesnt load and I get run time crash while loading the zstd library. I am adding screenshots for the synced gradle dependency for network module as well as main module. You can see the difference as network module synced dependency as "@aar" and the main module sync gradle dependnecy does not have "@aar". Kindly help to resolve the issue as I am not able to use zstd in my project.
Not sure what's the root cause. Can you show me the exception that is thrown? I have just checked the aar and it contains the native libraries:
$ jar -tf zstd-jni-1.5.5-4.aar
AndroidManifest.xml
R.txt
classes.jar
jni/
jni/arm64-v8a/
jni/arm64-v8a/libzstd-jni-1.5.5-4.so
jni/armeabi-v7a/
jni/armeabi-v7a/libzstd-jni-1.5.5-4.so
jni/x86/
jni/x86/libzstd-jni-1.5.5-4.so
jni/x86_64/
jni/x86_64/libzstd-jni-1.5.5-4.so
Hi Luben, Please find run time exception thrown :
Fatal Exception: java.lang.UnsatisfiedLinkError: dlopen failed: library "libzstd-jni-1.5.2-5.so" not found
Unsupported OS/arch, cannot find /linux/aarch64/libzstd-jni-1.5.2-5.so or load zstd-jni-1.5.2-5 from system libraries. Please try building from source the jar or providing libzstd-jni-1.5.2-5 in your system.
at java.lang.Runtime.loadLibrary0(Runtime.java:1081)
at java.lang.Runtime.loadLibrary0(Runtime.java:1003)
at java.lang.System.loadLibrary(System.java:1765)
at com.github.luben.zstd.util.Native.load(Native.java:97)
at com.github.luben.zstd.util.Native.load(Native.java:65)
at com.github.luben.zstd.ZstdDecompressCtx.<clinit>(ZstdDecompressCtx.java:12)
at com.abc.network.zstd.ZstdUtils.decompressData(ZstdUtils.kt:106)
at com.abc.network.NetworkRequest.parseNetworkResponse(NetworkRequest.java:352)
at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:144)
at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:111)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:90)
I hope you got the issue reported above. The zstd aar contains the native libraries but in multi module app architecture .so files are not getting loaded. Individually this works for separate modules. But when zstd gradle dependency is added with one sub module and then that sub module is added as gradle dependency to the main module the .so files are not loaded. I would request you to please go through my issue above and look at the screenshots attached.
Not sure I can help. Looks to me like mismatch between versions. If you use the above aar it should not try to load libraries from another version. I highly doubt there is an issue with that particular release, but you should be able to try with another one, more recent.
So did I, I`m working with Android Studio 2024.2.2.13 to build apk, and added dependencies in build.gradle file
dependencies { // implementation ......... implementation libs.zstd.jni }
debug and the logcat show:
java.lang.UnsatisfiedLinkError: dlopen failed: library "libzstd-jni-1.5.6-9.so" not found Unsupported OS/arch, cannot find /linux/aarch64/libzstd-jni-1.5.6-9.so or load zstd-jni-1.5.6-9 from system libraries. Please try building from source the jar or providing libzstd-jni-1.5.6-9 in your system
I extracted the apk package, and found that there is a "win" directory contains libzstd-jni-1.5.6-9.dll
I checked External Libraries, maybe the .so file is existing.
So, what happened?
This is the jar that is for normal java. For android you should use the aar. Your dependency should be declared as https://github.com/luben/ZstdAndroidExample/blob/master/app/build.gradle#L26C1-L26C59