AgoraIO / Docs-Source

A repository for the Agora Docs source content.
MIT License
20 stars 11 forks source link

Can't dynamically load .so files. #1444

Closed MaheshPhuyal02 closed 1 year ago

MaheshPhuyal02 commented 1 year ago

Hello, I tried to load .so files from file path: /storage/emulated/0/Android/data/app.yeah.apps.demo/files/lib/x86_64/...

RtcEngineConfig config = new RtcEngineConfig(); config.mContext = getBaseContext(); config.mAppId = appId; config.mNativeLibPath = "/storage/emulated/0/Android/data/app.yeah.apps.demo/files/lib/x86_64/"; config.mEventHandler = mRtcEventHandler;

Got error dlopen failed: library "/storage/emulated/0/Android/data/app.yeah.apps.demo/files/lib/x86_64/libagora-soundtouch.so" needed or dlopened by "/system/lib64/libnativeloader.so" is not accessible for the namespace "classloader-namespace"

I tested on android 9.0 and 13. What's the solution for this?

saudsami commented 1 year ago

The issue you're facing is that the library you're trying to load (libagora-soundtouch.so) is not accessible from the namespace in which your application's class loader resides. This issue is due to how Android enforces namespace isolation to improve security and prevent unauthorized access to system libraries.

Use the Application's Native Library Directory: Instead of loading libraries from a custom file path, consider using the native library directory provided by the Android system for your app. You can copy your .so files to the appropriate directories (lib/x86_64, lib/arm64-v8a, etc.) in the app/src/main/jniLibs directory of your Android project. This way, the libraries will be loaded from the correct location that is accessible to your app's class loader.

MaheshPhuyal02 commented 1 year ago

Thanks, It worked after moving libs inside path provided by method: context.getFilesDir() .