Discussion:
java.lang.UnsatisfiedLinkError: dlopen failed: library "../../../../libs/arm64-v8a/libhello.so
m***@gmail.com
2017-07-05 08:37:14 UTC
Permalink
Hi all,

I am trying to import the prebuilt native libraries to the Android app with
ndk support.

With editing the build.gradle file for the app module, and editing the
CMakeLists.txt file, the apk files can be built successfully.
There're two libraries in the apk file, like this:

lib
|_arm64-v8a
|___libnative-lib.so
|___libhello.so

However, when I am running this app, there will be one FATAL exception.
From the log, I got the UnsatisfiedLinkError.

I am very curious that the libraries are located in the `lib` directory of
the apk file, why does `dlopen` treat `libs/<arch>/` as the default search
path?

Thanks.

Best regards,
Minjun
--
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 post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/0105dc25-2c8a-4200-9d80-0278de7a0d5a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
m***@gmail.com
2017-07-06 03:29:31 UTC
Permalink
Updates:

I checked the installed path on the device, and I found the files are
installed to the "lib/arm64/" directory. I tried to duplicate the directory
to "libs/arm64-v8a", but it doesn't work.

Why does "dlopen" try to open "../../../../libs/arm64-v8a/libhello.so", but
there's no such directory in the app, is it hard-coded?

Thanks.
Post by m***@gmail.com
Hi all,
I am trying to import the prebuilt native libraries to the Android app
with ndk support.
With editing the build.gradle file for the app module, and editing the
CMakeLists.txt file, the apk files can be built successfully.
lib
|_arm64-v8a
|___libnative-lib.so
|___libhello.so
However, when I am running this app, there will be one FATAL exception.
From the log, I got the UnsatisfiedLinkError.
I am very curious that the libraries are located in the `lib` directory of
the apk file, why does `dlopen` treat `libs/<arch>/` as the default search
path?
Thanks.
Best regards,
Minjun
--
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 post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/51786a93-18ed-4f7e-84c6-2a717a76fee1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Andrew Esh
2017-07-06 17:49:10 UTC
Permalink
Why not just open the directory where the library actually is? Figure out
where the library is being installed by the packaging, and load it from
there.

Also, in Android O, there is another path component added to the library
path which is an un-guessable hash. The hash is changed every time
the app is installed, so you can't use a hardcoded path to dlopen the
library any more. To support this, I added a reverse JNI call from C to Java
to call "[context].getContext().getApplicationInfo().nativeLibraryDir;". If
you were to do this, it would solve your immediate problem, and it will
solve the Android O porting problem in the future.
Post by m***@gmail.com
Hi all,
I am trying to import the prebuilt native libraries to the Android app
with ndk support.
With editing the build.gradle file for the app module, and editing the
CMakeLists.txt file, the apk files can be built successfully.
lib
|_arm64-v8a
|___libnative-lib.so
|___libhello.so
However, when I am running this app, there will be one FATAL exception.
From the log, I got the UnsatisfiedLinkError.
I am very curious that the libraries are located in the `lib` directory of
the apk file, why does `dlopen` treat `libs/<arch>/` as the default search
path?
Thanks.
Best regards,
Minjun
--
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 post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/df28f5b5-8f55-4019-b432-56406989b55a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Alex Cohn
2017-07-07 14:57:47 UTC
Permalink
How do you load libhello.so in your app? Maybe it depends on other
libraries, that are not installed?

BR,
Alex
Post by m***@gmail.com
Hi all,
I am trying to import the prebuilt native libraries to the Android app
with ndk support.
With editing the build.gradle file for the app module, and editing the
CMakeLists.txt file, the apk files can be built successfully.
lib
|_arm64-v8a
|___libnative-lib.so
|___libhello.so
However, when I am running this app, there will be one FATAL exception.
From the log, I got the UnsatisfiedLinkError.
I am very curious that the libraries are located in the `lib` directory of
the apk file, why does `dlopen` treat `libs/<arch>/` as the default search
path?
Thanks.
Best regards,
Minjun
--
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 post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/18aba291-9919-49b9-9cda-4feddd8da056%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
m***@gmail.com
2017-07-10 02:11:33 UTC
Permalink
This post might be inappropriate. Click to display it.
Alex Cohn
2017-07-10 19:29:53 UTC
Permalink
There could be a problem with your toolchain. But with the linker, rather
than the compiler. If you set rpath for libhello.so, it's no good.

BR,
Alex
Post by m***@gmail.com
The libhello.so is only one dumb library with one simple function
(returning one int value).
I think I might have found the reason, but not sure.
The libhello.so is prebuilt with aarch64-linux-android- cross compiler,
but android studio seems using clang to compile native code. Do you know
if there are any special instructions to prebuilt the libraries without
android-studio? The libhello.so library works with the native CLI binary
under Android shell, but it might not work well with the clang-compiled
Android apps.
The error message might be misleading, when it says "dlopen() failed with
blah/blah/blah/xxx.so". The path ("../../../../libs/arm64-v8a/libhello.so")
should be updated to the actual path in the device accordingly, but it is
not updated, I don't know which part should be responsible to it....
Post by Alex Cohn
How do you load libhello.so in your app? Maybe it depends on other
libraries, that are not installed?
BR,
Alex
Post by m***@gmail.com
Hi all,
I am trying to import the prebuilt native libraries to the Android app
with ndk support.
With editing the build.gradle file for the app module, and editing the
CMakeLists.txt file, the apk files can be built successfully.
lib
|_arm64-v8a
|___libnative-lib.so
|___libhello.so
However, when I am running this app, there will be one FATAL exception.
From the log, I got the UnsatisfiedLinkError.
I am very curious that the libraries are located in the `lib` directory
of the apk file, why does `dlopen` treat `libs/<arch>/` as the default
search path?
Thanks.
Best regards,
Minjun
--
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 post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/ebc96610-da32-4ab2-a322-70225a8ceb40%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
m***@gmail.com
2017-07-14 03:36:58 UTC
Permalink
Thanks for your help. :D

I digged into all the options used by the ninja and cmake building system
in Android studio NDK support, and finally got the key linker options:

-Wl,-soname,libhello.so

This is important, and the file name (libhello.so) has to be the same with
the final library file put into the ndk project.
Post by Alex Cohn
There could be a problem with your toolchain. But with the linker, rather
than the compiler. If you set rpath for libhello.so, it's no good.
BR,
Alex
Post by m***@gmail.com
The libhello.so is only one dumb library with one simple function
(returning one int value).
I think I might have found the reason, but not sure.
The libhello.so is prebuilt with aarch64-linux-android- cross compiler,
but android studio seems using clang to compile native code. Do you
know if there are any special instructions to prebuilt the libraries
without android-studio? The libhello.so library works with the native
CLI binary under Android shell, but it might not work well with the
clang-compiled Android apps.
The error message might be misleading, when it says "dlopen() failed
with blah/blah/blah/xxx.so". The path ("
../../../../libs/arm64-v8a/libhello.so") should be updated to the actual
path in the device accordingly, but it is not updated, I don't know which
part should be responsible to it....
Post by Alex Cohn
How do you load libhello.so in your app? Maybe it depends on other
libraries, that are not installed?
BR,
Alex
Post by m***@gmail.com
Hi all,
I am trying to import the prebuilt native libraries to the Android app
with ndk support.
With editing the build.gradle file for the app module, and editing the
CMakeLists.txt file, the apk files can be built successfully.
lib
|_arm64-v8a
|___libnative-lib.so
|___libhello.so
However, when I am running this app, there will be one FATAL exception.
From the log, I got the UnsatisfiedLinkError.
I am very curious that the libraries are located in the `lib` directory
of the apk file, why does `dlopen` treat `libs/<arch>/` as the default
search path?
Thanks.
Best regards,
Minjun
--
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 post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/c52530fc-d2a8-4d55-8689-e69a2bf44488%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Alex Cohn
2017-07-15 13:11:32 UTC
Permalink
No, soname cannot be a problem. Also, we are not suspecting the part that
builds libhello.so, but rather the part that is dependent on it.

BR,
Alex
Post by m***@gmail.com
Thanks for your help. :D
I digged into all the options used by the ninja and cmake building system
-Wl,-soname,libhello.so
This is important, and the file name (libhello.so) has to be the same with
the final library file put into the ndk project.
Post by Alex Cohn
There could be a problem with your toolchain. But with the linker, rather
than the compiler. If you set rpath for libhello.so, it's no good.
BR,
Alex
Post by m***@gmail.com
The libhello.so is only one dumb library with one simple function
(returning one int value).
I think I might have found the reason, but not sure.
The libhello.so is prebuilt with aarch64-linux-android- cross compiler,
but android studio seems using clang to compile native code. Do you
know if there are any special instructions to prebuilt the libraries
without android-studio? The libhello.so library works with the native
CLI binary under Android shell, but it might not work well with the
clang-compiled Android apps.
The error message might be misleading, when it says "dlopen() failed
with blah/blah/blah/xxx.so". The path ("
../../../../libs/arm64-v8a/libhello.so") should be updated to the
actual path in the device accordingly, but it is not updated, I don't know
which part should be responsible to it....
Post by Alex Cohn
How do you load libhello.so in your app? Maybe it depends on other
libraries, that are not installed?
BR,
Alex
Post by m***@gmail.com
Hi all,
I am trying to import the prebuilt native libraries to the Android app
with ndk support.
With editing the build.gradle file for the app module, and editing the
CMakeLists.txt file, the apk files can be built successfully.
lib
|_arm64-v8a
|___libnative-lib.so
|___libhello.so
However, when I am running this app, there will be one FATAL
exception. From the log, I got the UnsatisfiedLinkError.
I am very curious that the libraries are located in the `lib`
directory of the apk file, why does `dlopen` treat `libs/<arch>/` as the
default search path?
Thanks.
Best regards,
Minjun
--
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 post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/a2076b74-b330-4f9e-8e5c-f385f458b7d0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
S.G. Vogel
2018-08-31 20:54:10 UTC
Permalink
Hi
You have a lot of good NDK answers on SO.
Can you answer this:

Hans' 2017 talk at googleio about managing native memory does not touch on
global reference use but shows that JNI can be wonky.

https://developer.android.com/training/articles/perf-jni says:

The global reference is guaranteed to be valid until you call
DeleteGlobalRef.

Do you have any experience in Android when this does not hold true?
Post by Alex Cohn
No, soname cannot be a problem. Also, we are not suspecting the part that
builds libhello.so, but rather the part that is dependent on it.
BR,
Alex
Post by m***@gmail.com
Thanks for your help. :D
I digged into all the options used by the ninja and cmake building system
-Wl,-soname,libhello.so
This is important, and the file name (libhello.so) has to be the same
with the final library file put into the ndk project.
Post by Alex Cohn
There could be a problem with your toolchain. But with the linker,
rather than the compiler. If you set rpath for libhello.so, it's no
good.
BR,
Alex
Post by m***@gmail.com
The libhello.so is only one dumb library with one simple function
(returning one int value).
I think I might have found the reason, but not sure.
The libhello.so is prebuilt with aarch64-linux-android- cross
compiler, but android studio seems using clang to compile native
code. Do you know if there are any special instructions to prebuilt the
libraries without android-studio? The libhello.so library works with
the native CLI binary under Android shell, but it might not work well with
the clang-compiled Android apps.
The error message might be misleading, when it says "dlopen() failed
with blah/blah/blah/xxx.so". The path ("
../../../../libs/arm64-v8a/libhello.so") should be updated to the
actual path in the device accordingly, but it is not updated, I don't know
which part should be responsible to it....
Post by Alex Cohn
How do you load libhello.so in your app? Maybe it depends on other
libraries, that are not installed?
BR,
Alex
Post by m***@gmail.com
Hi all,
I am trying to import the prebuilt native libraries to the Android
app with ndk support.
With editing the build.gradle file for the app module, and editing
the CMakeLists.txt file, the apk files can be built successfully.
lib
|_arm64-v8a
|___libnative-lib.so
|___libhello.so
However, when I am running this app, there will be one FATAL
exception. From the log, I got the UnsatisfiedLinkError.
I am very curious that the libraries are located in the `lib`
directory of the apk file, why does `dlopen` treat `libs/<arch>/` as the
default search path?
Thanks.
Best regards,
Minjun
--
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 post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/250428ef-c7bc-43c8-a29f-949c613ad865%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Alex Cohn
2017-07-18 18:58:28 UTC
Permalink
Note that there was a change for API 23 that may manifest itself in
described
behavior: https://android.googlesource.com/platform/bionic/+/master/android-changes-for-ndk-developers.md#Correct-soname_path-handling-Available-in-API-level-23

This still does not explain what in your toolchain could have triggered the
problem.

BR,
Alex
Post by m***@gmail.com
Thanks for your help. :D
I digged into all the options used by the ninja and cmake building system
-Wl,-soname,libhello.so
This is important, and the file name (libhello.so) has to be the same with
the final library file put into the ndk project.
Post by Alex Cohn
There could be a problem with your toolchain. But with the linker, rather
than the compiler. If you set rpath for libhello.so, it's no good.
BR,
Alex
Post by m***@gmail.com
The libhello.so is only one dumb library with one simple function
(returning one int value).
I think I might have found the reason, but not sure.
The libhello.so is prebuilt with aarch64-linux-android- cross compiler,
but android studio seems using clang to compile native code. Do you
know if there are any special instructions to prebuilt the libraries
without android-studio? The libhello.so library works with the native
CLI binary under Android shell, but it might not work well with the
clang-compiled Android apps.
The error message might be misleading, when it says "dlopen() failed
with blah/blah/blah/xxx.so". The path ("
../../../../libs/arm64-v8a/libhello.so") should be updated to the
actual path in the device accordingly, but it is not updated, I don't know
which part should be responsible to it....
Post by Alex Cohn
How do you load libhello.so in your app? Maybe it depends on other
libraries, that are not installed?
BR,
Alex
Post by m***@gmail.com
Hi all,
I am trying to import the prebuilt native libraries to the Android app
with ndk support.
With editing the build.gradle file for the app module, and editing the
CMakeLists.txt file, the apk files can be built successfully.
lib
|_arm64-v8a
|___libnative-lib.so
|___libhello.so
However, when I am running this app, there will be one FATAL
exception. From the log, I got the UnsatisfiedLinkError.
I am very curious that the libraries are located in the `lib`
directory of the apk file, why does `dlopen` treat `libs/<arch>/` as the
default search path?
Thanks.
Best regards,
Minjun
--
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 post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/67230783-341f-45f8-a7b2-9bcdcbedfc9b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Sonaali
2018-08-28 10:29:22 UTC
Permalink
Hi, i am facing a similar issue with my application. just wanted to ask
@minjun, how you finally solved it??
by adding the linker flags only, was it??
Thanks and regards,
Post by Alex Cohn
Note that there was a change for API 23 that may manifest itself in
https://android.googlesource.com/platform/bionic/+/master/android-changes-for-ndk-developers.md#Correct-soname_path-handling-Available-in-API-level-23
This still does not explain what in your toolchain could have triggered
the problem.
BR,
Alex
Post by m***@gmail.com
Thanks for your help. :D
I digged into all the options used by the ninja and cmake building system
-Wl,-soname,libhello.so
This is important, and the file name (libhello.so) has to be the same
with the final library file put into the ndk project.
Post by Alex Cohn
There could be a problem with your toolchain. But with the linker,
rather than the compiler. If you set rpath for libhello.so, it's no
good.
BR,
Alex
Post by m***@gmail.com
The libhello.so is only one dumb library with one simple function
(returning one int value).
I think I might have found the reason, but not sure.
The libhello.so is prebuilt with aarch64-linux-android- cross
compiler, but android studio seems using clang to compile native
code. Do you know if there are any special instructions to prebuilt the
libraries without android-studio? The libhello.so library works with
the native CLI binary under Android shell, but it might not work well with
the clang-compiled Android apps.
The error message might be misleading, when it says "dlopen() failed
with blah/blah/blah/xxx.so". The path ("
../../../../libs/arm64-v8a/libhello.so") should be updated to the
actual path in the device accordingly, but it is not updated, I don't know
which part should be responsible to it....
Post by Alex Cohn
How do you load libhello.so in your app? Maybe it depends on other
libraries, that are not installed?
BR,
Alex
Post by m***@gmail.com
Hi all,
I am trying to import the prebuilt native libraries to the Android
app with ndk support.
With editing the build.gradle file for the app module, and editing
the CMakeLists.txt file, the apk files can be built successfully.
lib
|_arm64-v8a
|___libnative-lib.so
|___libhello.so
However, when I am running this app, there will be one FATAL
exception. From the log, I got the UnsatisfiedLinkError.
I am very curious that the libraries are located in the `lib`
directory of the apk file, why does `dlopen` treat `libs/<arch>/` as the
default search path?
Thanks.
Best regards,
Minjun
--
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 post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/6b886826-67d4-45f3-b4a1-66a73a0fff60%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...