1

I'm trying to load a .so library from a specified "allowed" path that is:

/data/data/my.package.name/mylibrary.so

I know that I can't just put my lib to /sdcard/ for security purpose (and this is fine).

I'm trying to load the library with:

System.load("/data/data/my.package.name/mylibrary.so");

But for some reasons I'm failing to understand, my app crash with:

java.lang.UnsatisfiedLinkError: dlopen failed: library "/data/data/my.package.name/mylibrary.so" not found

Running the app in Monitor I can also read:

avc: denied { read } for name="mylibrary.so" dev=tmpfs ....... tclass=file permissive=0

This looks like a SELinux issue. I've also checked the library permission in adb shell (from a root shell) and they looks okay.

I know that since Android Nougat it isn't possible to load system library, but this isn't a system lib.

Is there anything I can try?

Thank you very much

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Luca D'Amico
  • 3,192
  • 2
  • 26
  • 38
  • 1
    Why not just compile the library into the APK? If the answer is "because we are downloading the `.so` file", bear in mind that [this may violate Google's developer policies](https://play.google.com/about/privacy-security-deception/malicious-behavior/). – CommonsWare May 27 '18 at 18:13
  • @CommonsWare just for fun and learning. That's all. This is just an experimet, not something I'm doing for work ;) – Luca D'Amico May 27 '18 at 18:17
  • Did you tried with getApplicationInfo().nativeLibraryDir?? – E.Abdel May 27 '18 at 18:45
  • @E.Abdel why should I try that? i don't want to load the lib from the nativeLibraryDir – Luca D'Amico May 27 '18 at 19:14
  • Why not? It gives you the exact native libraries path of an installed app, take a look https://stackoverflow.com/a/16806802/5458344 – E.Abdel May 27 '18 at 19:26
  • 1
    I know that, but it is not what I'm trying to do: I want to load a lib from a custom path. Thanks for your help, but I'm not interested in the traditional way to load libs. EDIT: also the lib is not present at build time, it is dropped from the assets (after being Hex-edited on the fly). – Luca D'Amico May 27 '18 at 19:34

0 Answers0