Loading C library in Android

2

I have little to no understanding how low-level programming languages work, so please bear with me. I need to load compiled C (.so file) library into android 6.0+ (SdkVersion: 23+)

Using:

static {
    System.loadLibrary("dsdrv");
}

I get an error:

FATAL EXCEPTION: main
Process: com.logicants.scanner3, PID: 11415
java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app/com.logicants.scanner3-1/lib/arm/libdsdrv.so" has unexpected e_machine: 3
    at java.lang.Runtime.loadLibrary(Runtime.java:372)
    at java.lang.System.loadLibrary(System.java:1076)
    at com.logicants.scanner3.MainActivity.<clinit>(MainActivity.java:13)
    at java.lang.Class.newInstance(Native Method)
    at android.app.Instrumentation.newActivity(Instrumentation.java:1072)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2478)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2665)
    at android.app.ActivityThread.-wrap11(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1499)
    at android.os.Handler.dispatchMessage(Handler.java:111)
    at android.os.Looper.loop(Looper.java:207)
    at android.app.ActivityThread.main(ActivityThread.java:5765)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:683)

I did some digging on the internet and found this: https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-runtime

"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."

So, basically it fails due to: TEXTREL

readelf -a dsdrv.so | grep TEXTREL

Does not return anything

readelf -d dsdrv.so

Returns:

 Dynamic section at offset 0x5bd28 contains 24 entries:
   Tag        Type                         Name/Value
  0x00000001 (NEEDED)                     Shared library: [libpthread.so.0]
  0x00000001 (NEEDED)                     Shared library: [libstdc++.so.6]
  0x00000001 (NEEDED)                     Shared library: [libm.so.6]
  0x00000001 (NEEDED)                     Shared library: [libgcc_s.so.1]
  0x00000001 (NEEDED)                     Shared library: [libc.so.6]
  0x0000000c (INIT)                       0xd3bc
  0x0000000d (FINI)                       0x4aec8
  0x6ffffef5 (GNU_HASH)                   0xd4
  0x00000005 (STRTAB)                     0x4f30
  0x00000006 (SYMTAB)                     0x1930
  0x0000000a (STRSZ)                      24307 (bytes)
  0x0000000b (SYMENT)                     16 (bytes)
  0x00000003 (PLTGOT)                     0x5d154
  0x00000002 (PLTRELSZ)                   2304 (bytes)
  0x00000014 (PLTREL)                     REL
  0x00000017 (JMPREL)                     0xcabc
  0x00000011 (REL)                        0xb5e4
  0x00000012 (RELSZ)                      5336 (bytes)
  0x00000013 (RELENT)                     8 (bytes)
  0x6ffffffe (VERNEED)                    0xb4e4
  0x6fffffff (VERNEEDNUM)                 5
  0x6ffffff0 (VERSYM)                     0xae24
  0x6ffffffa (RELCOUNT)                   44
  0x00000000 (NULL)                       0x0

So, I'm assuming it fails due to one of the Shared libraries. I do not have source code of the library just the compiled *.so file.

How can I resolve this? Is it possible to decompile *.so file and recompile it again, so it would not use TEXTREL.

android
c
android-ndk
asked on Stack Overflow Aug 3, 2017 by user2821023

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0