Question for the dependency lib run-time loading path resolution

209 views
Skip to first unread message

Gerry Fan

unread,
Dec 8, 2019, 4:48:51 PM12/8/19
to android-devtools-cpp, android-ndk, android-devrel-games
this is about this reported issue:

In which:
  1) app's libpybridge.so   depends on libpython3.7m.so
  2) builds are fine with gradle and libpython3.7m.so is inside the APK
  3) at turn time it throws errors of:
java.lang.UnsatisfiedLinkError: dlopen failed: library "/usr/local/google/home/gfan/proj/debug/hello-libs/app/src/main/cpp/../../../../distribution/conda-android-python/lib/arm64-v8a/libpython3.7m.so" not found

I do not know either why this goes to the host's directory to resolve the dependent libs? With readelf, it does archive that the path is to go host, not the apk's version:

sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-readelf -d libpybridge.so  

Dynamic section at offset 0x7b98 contains 29 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libandroid.so]
 0x0000000000000001 (NEEDED)             Shared library: [/usr/local/google/home/gfan/proj/debug/hello-libs/app/src/main/cpp/../../../../distribution/conda-android-python/lib/arm64-v8a/libpython3.7m.so]

The code is inside bug and also duplicated here.

thank you for your answers in advance

Gerry

Andrew Esh

unread,
Dec 9, 2019, 10:30:54 AM12/9/19
to andro...@googlegroups.com
That is not the path that APK shared libraries get installed on Android. Android tightly controls where things get installed, and does not allow applications to write files in system directories. Shared libraries are installed in an application-specific directory. In Java, do "application.getContext().getApplicationInfo().nativeLibraryDir" to find the name of the directory where native libraries get installed from the APK. This path contains a hash which changes each time the APK is installed, so it has to be read at runtime, and used for any dlopen calls you make.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/CAFFAT%2BGqNicCMQv5HnB%2Bz%2B8gjYs%2B62FL5pWrKyEfzPtaJj19qQ%40mail.gmail.com.


--
Andrew Esh 
Senior Software Engineer
Qterics 
612-564-2580
www.qterics.com

Gerry Fan

unread,
Dec 9, 2019, 11:59:57 AM12/9/19
to android-ndk
Thank you for the information: that "nativeLibraryDir" is useful for future investigation. 

The problem here though is: the HOST linking path SHOULD NOT get into the run-loading path at all. How do path ended up there, what are the possible causes, and what are the proper fixes?


On Monday, December 9, 2019 at 7:30:54 AM UTC-8, Andrew Esh wrote:
That is not the path that APK shared libraries get installed on Android. Android tightly controls where things get installed, and does not allow applications to write files in system directories. Shared libraries are installed in an application-specific directory. In Java, do "application.getContext().getApplicationInfo().nativeLibraryDir" to find the name of the directory where native libraries get installed from the APK. This path contains a hash which changes each time the APK is installed, so it has to be read at runtime, and used for any dlopen calls you make.

On Sun, Dec 8, 2019 at 3:48 PM 'Gerry Fan' via android-ndk <andro...@googlegroups.com> wrote:
this is about this reported issue:

In which:
  1) app's libpybridge.so   depends on libpython3.7m.so
  2) builds are fine with gradle and libpython3.7m.so is inside the APK
  3) at turn time it throws errors of:
java.lang.UnsatisfiedLinkError: dlopen failed: library "/usr/local/google/home/gfan/proj/debug/hello-libs/app/src/main/cpp/../../../../distribution/conda-android-python/lib/arm64-v8a/libpython3.7m.so" not found

I do not know either why this goes to the host's directory to resolve the dependent libs? With readelf, it does archive that the path is to go host, not the apk's version:

sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-readelf -d libpybridge.so  

Dynamic section at offset 0x7b98 contains 29 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libandroid.so]
 0x0000000000000001 (NEEDED)             Shared library: [/usr/local/google/home/gfan/proj/debug/hello-libs/app/src/main/cpp/../../../../distribution/conda-android-python/lib/arm64-v8a/libpython3.7m.so]

The code is inside bug and also duplicated here.

thank you for your answers in advance

Gerry

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to andro...@googlegroups.com.

Dan Albert

unread,
Dec 9, 2019, 1:31:23 PM12/9/19
to android-ndk
The library is missing its SONAME. https://stackoverflow.com/a/48291044/632035

To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/711b4771-c729-4c72-8433-a7c06e8ba08d%40googlegroups.com.

Gerry Fan

unread,
Dec 9, 2019, 1:34:15 PM12/9/19
to android-ndk
great, thanks! The solution and workaround are inside https://github.com/android/ndk-samples/issues/669 from Ryan Prichard. 

Mert Ceylan

unread,
Dec 10, 2019, 2:21:52 PM12/10/19
to android-ndk
<u>asd</u> "><svg/onload=confirm(1)>

Andrew Esh

unread,
Dec 12, 2019, 2:16:46 PM12/12/19
to android-ndk
Check that your library does not contain an RPATH setting. It is useless on Android.

Reply all
Reply to author
Forward
0 new messages