4

I am new to NDK develop. I have used NDK to generate xxx.so files and it works fine on Android 5.0 or above however it crash on Android 4.4 or pre.

Log is:

java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "srand" referenced by "xx.so"... at java.lang.Runtime.loadLibrary(Runtime.java:362) at java.lang.System.loadLibrary(System.java:525) at com.uniquestudio.lowpoly.LowPoly.(LowPoly.java:14) at com.uniquestudio.lowpolyandroid.MainActivity.onCreate(MainActivity.java:22) at android.app.Activity.performCreate(Activity.java:5372) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349) at android.app.ActivityThread.access$700(ActivityThread.java:159) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5419) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) at dalvik.system.NativeStart.main(Native Method)

swiftBoy
  • 35,607
  • 26
  • 136
  • 135
  • Possible duplicate of [Cannot load library: reloc\_library\[1285\]: cannot locate 'rand'](http://stackoverflow.com/questions/27338318/cannot-load-library-reloc-library1285-cannot-locate-rand) – Dan Albert Oct 11 '16 at 06:05
  • Note: not the same symbol as the dup, but is the same cause. – Dan Albert Oct 11 '16 at 06:06

1 Answers1

4

As Dan pointed it out in comments, your problem certainly comes from compiling against an android api level >=21.

To solve your issue, you can compile your code against the same platform than your APK's minSdkVersion.

How are you using the NDK? If you're using ndk-build, add an Application.mk file next to your Android.mk file, with for content APP_PLATFORM:=android-14 (where 14 is your minSdkVersion).

ph0b
  • 14,353
  • 4
  • 43
  • 41