8

My Android application is crashing and giving me the following error message:

java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate

shizhen
  • 12,251
  • 9
  • 52
  • 88
Subramanyam G
  • 103
  • 1
  • 1
  • 10

7 Answers7

15

Crash is coming because of following fact that has been changed in Android M

"On previous versions of Android, if your app requested the system to load a shared library with text relocations, the system displayed a warning but still allowed the library to be loaded. Beginning in this release, the system rejects this library if your app's target SDK version is 23 or higher. To help you detect if a library failed to load, your app should log the dlopen(3) failure, and include the problem description text that the dlerror(3) call returns. To learn more about handling text relocations, see this guide"

for more details please refer to this link

Liuting
  • 1,098
  • 17
  • 35
dex
  • 5,182
  • 1
  • 23
  • 41
  • 1
    While I've experienced this on Android 6 (23), the same APK (target 24) on my Nexus 6P (Android 7, 24) does not exhibit the same problem. Any ideas why? – Mark Sep 05 '16 at 10:35
  • @MarkCarter I need to check what has been changed in Android N that your are not observing this crash ! – dex Sep 05 '16 at 21:19
  • 1
    I can confirm, for the same APK (armeabi-v7a only), the crash happens on 23 (emulator and N5) but not on 24 (emulator and N6P) – Mark Sep 06 '16 at 00:50
  • I'm having the same failure on Android 6 (arm64 build) devices that does not fail on Android 7 device (unmodified Nexus 6 in my case for 7.0 device), both real hardware. ALSO IMPORTANT to try: it only fails the very first time the app is run after apk is installed. If I exit(2) the app (or reboot device) and start the app a second time, it works fine! App it built for SDK 25 using NDK 13B. – RoundSparrow hilltx Mar 18 '17 at 11:00
  • What does "shared library with text relocations" mean? – getsadzeg Mar 26 '17 at 16:42
3

Before anything I must say that I do not understand all the specifics behind that subject, but I'll try to guide you through the path that helped me.

I saw that that problem appeared only when using target version as 23. Reading other posts was easy to identify that that happened with libs compiled with older ndk tools (ndk-build, to be more specific, but I do not know exactly if that tool came later for fulfilling new needs).

It happened with me using libiconv, a dependency from ZBar project. So I thought that recompiling it would help, and helped. I used the ndk-build tool to recompile zbar and iconv libs.

I hope it suffices.

Community
  • 1
  • 1
  • I would suggest to look at [ZBar open discussion](https://sourceforge.net/p/zbar/discussion/2308158/) and [discussion about the text relocations](https://sourceforge.net/p/zbar/discussion/2308158/thread/ee6a4870/). Other links that helped me: [explanation about text relocations](http://slowbutdeadly.blogspot.com.br/2015/09/javalangunsatisfiedlinkerror-dlopen.html) and [iconv Android port](http://danilogiulianelli.blogspot.com.br/2012/12/how-to-cross-compile-libiconv-for.html) – Andre Luiz Fernandes de Mello May 05 '16 at 17:20
  • http://stackoverflow.com/questions/33152903/zbar-barcode-scanning-library-not-working-when-using-target-sdk-version-23-in-gr#comment54156643_33153379 another resolution – Andre Luiz Fernandes de Mello May 05 '16 at 20:38
2

This is related to Android 6.0 (Marshmallow) switching from OpenSSL to BoringSSL.

Your exception is occurring in the referenced library code. Contact the vendor for a fix or manually include the OpenSSL libraries to avoid the issue.

Also see: https://sourcedna.com/blog/20150806/predicting-app-crashes-on-android-m.html

duffymo
  • 305,152
  • 44
  • 369
  • 561
user2271109
  • 104
  • 2
  • That post no longer exists at that address, so here is the archive.org copy: https://web.archive.org/web/20170131094026/https://sourcedna.com/blog/20150806/predicting-app-crashes-on-android-m.html – ctd Nov 22 '22 at 18:41
2

as a simple answer, you just need to target android 22 sdk instead of android 23 in your build configuration. For example with gradle use:

defaultConfig {
  targetSdkVersion 22
}
Sloosh
  • 1,681
  • 1
  • 10
  • 14
1

Try to change targetSdkVersion in build.gradle to 22 and APP_PLATFORM := android-22 in application.mk. That worked in my environment.

FlipperPA
  • 13,607
  • 4
  • 39
  • 71
asdf
  • 97
  • 1
  • 10
1

Not sure if this will help someone or not but I had similar error and this is how it got fixed for me. My problem was i was having a library module in which I used sqlchiper .so files, these .so files were in my app module, but the dependency to implement this sqlitechiper was in library module build.gradle.

api 'net.xxxx:android-database-sqlcipher:xxx@aar'

But we decided to convert the library module as .aar file and add it to app module as a dependency and this is when i got the crash java.lang.UnsatisfiedLinkError: dlopen failed:. And i was using a sqlitechiper.jar in app layer so i didn't get any compile time errors as well.

Adding the dependency in app layer and removing the sqlitechiper.jar file dependency from app layer has fixed the issue.

After reading several stackoverflow answers I understood that dependencies that are added in .aar files don't include transitively in app layer if u r adding .aar file directly, if u r adding it as a dependency using compile/api/implementation then those will be added transitively.

Community
  • 1
  • 1
Murli
  • 524
  • 6
  • 11
0

I could get it work in more recent SdkVersions by adding the following line to the NDK in the gradle script

android.ndk {
     <...> //rest of lines
     cppFlags.add("-fPIC") //generate position independent code
     <...> 
}
Carlos Hoyos
  • 694
  • 9
  • 10