Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.SO file not packed with APK file #333

Open
firozanawar opened this issue Nov 20, 2024 · 3 comments
Open

.SO file not packed with APK file #333

firozanawar opened this issue Nov 20, 2024 · 3 comments

Comments

@firozanawar
Copy link

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.

MainModule
NetworkModule

@luben
Copy link
Owner

luben commented Nov 21, 2024

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

@firozanawar
Copy link
Author

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.

@luben
Copy link
Owner

luben commented Nov 22, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants