Link to the shared library version in Android NDK

I am trying to load two shared libraries in an Android application through a loadLibrary call:

 System.loadLibrary("mywrapper"); System.loadLibrary("crypto"); 

I keep on running "UnsatisfiedLinkError". Here is a more detailed version of the error.

 Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: link_image[1969]: 130 could not load needed library 'libcrypto.so.1.0.0' for 'libmywrapper.so' (load_library[1111]: Library 'libcrypto.so.1.0.0' not found) 

Any ideas?

After spending some time, I found out that Android does not support library versions. Has anyone encountered the same problem?

+6
source share
3 answers

I had the same issue with creating libwebsockets for Android, which needs to be linked to OpenSSL. I am using libssl.so as an example. You must do the same for linked .so files.

 Before: huiying@huiying-PORTEGE-R835 :~$ objdump -p libssl.so | grep so libssl.so: file format elf32-little NEEDED libcrypto.so.1.0.0 NEEDED libdl.so NEEDED libc.so SONAME libssl.so.1.0.0 After huiying@huiying-PORTEGE-R835 :~$ rpl -R -e .so.1.0.0 "_1_0_0.so" libssl.so Replacing ".so.1.0.0" with "_1_0_0.so" (case sensitive) (partial words matched) . A Total of 2 matches replaced in 1 file searched. huiying@huiying-PORTEGE-R835 :~$ objdump -p libssl.so | grep so libssl.so: file format elf32-little NEEDED libcrypto_1_0_0.so NEEDED libdl.so NEEDED libc.so SONAME libssl_1_0_0.so And don't forget to change file name "libssl.so" to "libssl_1_0_0.so". 

Failure is working. I have an Android app to prove it. See my request at http://computervisionandjava.blogspot.com/2015/05/trouble-with-versioned-shared-libraries.html .

+4
source

Android seems to have a problem loading library versions. The problem was due to the library name in my case libcrypto.so.1.0.0. Even if you rename the library and try to load it as a pre-created shared library into the android file file, it fails (this should be because the library name is somehow embedded in the file. And any library that links to it associated with a library with the same name)

I hope there are other ways when it comes to handling libraries with version names in android.

I am currently wrapping the problem together using the static openssl libraries and linking them to my own shared library.

+2
source

The year 2014 is still not supported by shared library versions. So I made a script to fix SONAME. Just specify a script to enter dir where all versions of libs are located. Then check the unver output disk.

 #!/bin/bash DIR="$1" if [ "$DIR" == "" ]; then echo "Usage: fix-soname.sh <target dir>" exit fi if [ ! -d $DIR ]; then echo "Not found: $DIR" exit fi OUT="$DIR/unver" echo "Input=$DIR" echo "Output=$OUT" CWD=$(pwd) cd $DIR # prep dirs mkdir -p $OUT rm -f -R $OUT/* # rename libs and copy to out dir find "$DIR" -type f -name '*.so*' | while read FILE; do NAME=$(basename "$FILE") SONAME=$NAME while read SYMLINK; do X=$(basename "$SYMLINK") #echo "$X (${#X}) -> $NAME (${#NAME})" if [ "${#X}" -lt "${#SONAME}" ]; then SONAME=$X fi done<<EOT `find -L $DIR -samefile $FILE` EOT #echo $SONAME cp -f $SONAME $OUT/ done # patch libs in out dir find "$OUT" -type f -name '*.so*' | while read FILE; do # get file name without path NAME=$(basename "$FILE") # extract SONAME from shared lib SONAME=`readelf -d $FILE | grep '(SONAME)' | grep -P '(?<=\[)(lib.*?)(?=\])' -o` #echo "$NAME [$SONAME]" # patch SONAME if required if [ "$NAME" != "$SONAME" ]; then L1=${#NAME} L2=${#SONAME} LDIFF=$((L2-L1)) #echo "$NAME [$SONAME] ($LDIFF)" if [ "$LDIFF" -gt "0" ]; then SONEW=$NAME for (( c=1; c<=$LDIFF; c++ )); do SONEW+="\x00" done echo "$NAME [$SONAME] -> $SONEW ($LDIFF)" rpl -R -e "$SONAME" "$SONEW" $OUT fi fi done cd $CWD 
+2
source

Source: https://habr.com/ru/post/920514/


All Articles