Search code examples
androidandroid-6.0-marshmallowloadlibrarytarget-sdk

Android 6.0 Preview 3 device (with target sdk 23) , System.loadLibrary is fail


(1) Build State
* Target SDK : 23

(1-1) Build State - ADD
* eclipse - indigo
* ndk - android-ndk-r7c

(2) Device State
* device OS : Android 6.0 preview 3 OS , Android 6.0
* device name : Nexus 9

(3) code

case 1 System.loadLibrary("game");

case 2 System.load(“/lib/libc2scommon.so");

(4) Error Msg

case 1

09-30 19:06:56.091: D/AndroidRuntime(3512): Shutting down VM
09-30 19:06:56.091: E/AndroidRuntime(3512): FATAL EXCEPTION: main
09-30 19:06:56.091: E/AndroidRuntime(3512): Process: <MY_APP_ID>, PID: 3512
09-30 19:06:56.091: E/AndroidRuntime(3512): java.lang.UnsatisfiedLinkError: dlopen failed: /data/app/<MY_APP_ID>-1/lib/arm/libgame.so: has text relocations
09-30 19:06:56.091: E/AndroidRuntime(3512):     at java.lang.Runtime.load(Runtime.java:332)
09-30 19:06:56.091: E/AndroidRuntime(3512):     at java.lang.System.load(System.java:1069)

case 2

09-30 18:43:42.390: E/AndroidRuntime(3082): Process: <MY_APP_ID> , PID: 3082
09-30 18:43:42.390: E/AndroidRuntime(3082): java.lang.UnsatisfiedLinkError: dlopen failed: /data/app/<MY_APP_ID>-2/lib/arm/libgame.so: has text relocations
09-30 18:43:42.390: E/AndroidRuntime(3082):     at java.lang.Runtime.load(Runtime.java:332)
09-30 18:43:42.390: E/AndroidRuntime(3082):     at java.lang.System.load(System.java:1069)


What is Problem?
Target SDK 22 is not problem.
help plz.


Solution

  • If you're targetting SDK 23 or higher shared libraries that have text relocations are now rejected. This is documented here: https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-runtime

    You'll have to fix them, which means you need to have access to the native code and NDK prepared. Easiest workaround is to add -fpic or -fPIC to your LOCAL_CFLAGS in your Android.mk file, and then rebuild the libraries.