2

hope you can help me here. I managed to create my native activity project and packaged it. In the libs folder I have a shared library that is loaded dynamically (dlopen) within the native activity. I know that the package libs are copied into: /data/data/packagename/lib but how can I access it using dlopen? Is that possible? I thought I can access it using just the local folder name, like: ./libMySharedLibrary because they all are in the APK/libs subfolder. Does anyone how to get to the correct foldername or how to get access to those shared libraries?

yaakuro
  • 191
  • 1
  • 4

1 Answers1

1

Dynamic linker already knows about your package private libraries - just pass basename and all should be OK:

dlopen("libawesome.so", RTLD_LAZY);

P.S. To avoid surprises you should ensure that your library name unique and doesn't clash with system ones (these are placed at /system/lib and /vendor/lib, also check lib64 directories on 64-bit devices).

Sergio
  • 8,099
  • 2
  • 26
  • 52
  • Let's say my package name is: **com.android.example**. When I do: **adb shell run-as com.android.example** and look into the **/lib** folder I can't see my shared library. I can see the shared library in the .apk file but after installing it with **ant installd** it is not in that folder. Is the shared library supposed to be copied into that folder? – yaakuro Jul 31 '16 at 13:19
  • @yaakuro AFAIK native libs are copied to [`nativeLibraryDir`](https://developer.android.com/reference/android/content/pm/ApplicationInfo.html#nativeLibraryDir). And seems like it is not always your package `lib` directory. Anyway the question was not about library location but about proper way to load them in native code. Did you try using `dlopen()` with only library basename? – Sergio Aug 01 '16 at 07:12