python3-android icon indicating copy to clipboard operation
python3-android copied to clipboard

dynamic library does not have SONAME

Open GRRedWings opened this issue 4 years ago • 7 comments

In trying to figure out issues I'm having on older devices running 6.0.1, I'm wondering if some of my issues are that I had to change how I import the library. In looking back at my fork, the dynamic library has an SONAME, the current version coming from this fork are not. In looking back at Issue 18 I noticed that my errors was showing the windows style path, and I wonder if it's causing some of my issues. As described here

On a side note, I also see that Python 3.9b5 is available. I tried adding a similar path to the configure.ac, but I didn't have much luck.

GRRedWings avatar Sep 03 '20 16:09 GRRedWings

Adding SONAME requires some non-trivial patches to setup.py and/or distutils. I'd like a self-contained App to test before investing time into SONAME stuffs.

Also, I really suggest you to build static library libpython.a and link your JNI library to libpython.a so to get rid of all the issues around dynamic linking.

yan12125 avatar Sep 04 '20 08:09 yan12125

I played around and added the following patch to configure.ac. I realize this is hard coded, but this added the SONAME to my dynamic library, and fixed some of my issues.

`diff --git a/configure.ac b/configure.ac index 73ee71c6d2..a62edaebae 100644 --- a/configure.ac 2020-09-03 13:02:27.847717033 -0700 +++ b/configure.ac 2020-09-03 13:14:11.101958236 -0700 @@ -890,8 +890,9 @@ AC_SUBST(MULTIARCH_CPPFLAGS)

AC_MSG_CHECKING([for -Wl,--no-as-needed]) +LDFLAGS="$LDFLAGS -Wl,-soname,libpython3.9.so" save_LDFLAGS="$LDFLAGS" LDFLAGS="$LDFLAGS -Wl,--no-as-needed" AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])], [NO_AS_NEEDED="-Wl,--no-as-needed" AC_MSG_RESULT([yes])],

`

GRRedWings avatar Sep 04 '20 14:09 GRRedWings

I have tried to get the static library to work, but I have not had much luck. Any chance you can point me in the right direction if you recommend that, or update my test app to show how that would work?

GRRedWings avatar Sep 11 '20 12:09 GRRedWings

Sorry, but I don't have much time recently for testing it. Mind to share error messages you've got? (I'm not asking for a complete example this time - I know preparing it is very time consuming :P)

I think after rebuilding python3-android as static libraries and remove loadLibrary("python3.9") are first steps?

yan12125 avatar Sep 16 '20 16:09 yan12125

I feel I'm doing something wrong. I've tried adding these lines to CMakeLists

find_library(LIB_TO_INCLUDE ClassLibrary ${distribution_dir}/jnilibs/${ANDROID_ABI})
target_link_libraries(python39 ${LIB_TO_INCLUDE})

but get this error

CMake Error at CMakeLists.txt:21 (target_link_libraries):
Cannot specify link libraries for target "python39" which is not built by
this project.

I've tried to just change what is currently in the CMakesList.txt and use STATIC instead of SHARED and .a instead of .o. The app then compiles, but crashes at runtime with CMakeLists

add_library(python39 STATIC IMPORTED)
set_target_properties(python39 PROPERTIES IMPORTED_LOCATION ${distribution_dir}/${ANDROID_ABI}/libpython3.9.a)

Runtime Output

2020-09-17 10:23:49.568 29855-29855/com.example.pythontest E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.pythontest, PID: 29855
    java.lang.UnsatisfiedLinkError: dlopen failed: library "libpython3.9.so" not found

At this point I feel I need to create a fork of your project that has my hack in configure.ac so I can at least get back to that if needed. Maybe we can get a static build working, but other then a requests library input failing on my 32 bit 6.0.1 device, everything works with this SONAME patch.

GRRedWings avatar Sep 17 '20 14:09 GRRedWings

As an added note. I'm pretty much giving up on the 1 device that doesn't run this. I tracked it down to the requests library (https://requests.readthedocs.io/en/master/) It appears to fail in urllib3 when trying to make the following import

from __future__ import absolute_import

I tried removing these imports, but it only created other issues. Just sharing for the sake of sharing, not sure it helps anyone understand my issues.

GRRedWings avatar Sep 17 '20 19:09 GRRedWings

java.lang.UnsatisfiedLinkError: dlopen failed: library "libpython3.9.so" not found

Hmm, that's strange. If you want to continue the state library approach, could you check if readelf -d libpythonthread.so still has libpython3.9.so (it shouldn't now), and the System.loadLibrary("python3.9"); has been removed from Java files?

It appears to fail in urllib3 when trying to make the following import

Yet another strange stuff... absolute_import is enabled by default on Python 3.x.

yan12125 avatar Sep 20 '20 15:09 yan12125