Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocos2dx: dlopen failed: cannot locate symbol "atof" referenced by "libcocos2dcpp.so"

I am trying to run my cocos2d-x game on android devices, it works perfectly on android 5.0(lollipop), but crashes on lower android versions. I am getting the following error:

02-25 10:41:09.787: E/ResourceType(18090): 0x5ad385b8: Failed to ResTable::remove() cookie = 0x3, not last table. mHeaders.size() = 4. Warning for spontaneous crashes when the garbage collector runs. 02-25 10:41:09.797: E/asset(18090): Error removing runtime skin resource (cookie 0x3) 02-25 10:41:09.797: I/asset(18090): Problem removing all runtime skin resources 02-25 10:41:09.817: D/dalvikvm(18090): Trying to load lib /data/app-lib/com.example.game-2/libcocos2dcpp.so 0x418c9ce8 02-25 10:41:09.817: E/dalvikvm(18090): dlopen("/data/app-lib/com.example.game-2/libcocos2dcpp.so") failed: dlopen failed: cannot locate symbol "atof" referenced by "libcocos2dcpp.so"... 02-25 10:41:09.817: W/dalvikvm(18090): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/example/game/game; 02-25 10:41:09.817: W/dalvikvm(18090): Class init failed in newInstance call (Lcom/example/game/game;) 02-25 10:41:09.817: D/AndroidRuntime(18090): Shutting down VM 02-25 10:41:09.817: W/dalvikvm(18090): threadid=1: thread exiting with uncaught exception (group=0x415af8b0) 02-25 10:41:09.827: E/AndroidRuntime(18090): FATAL EXCEPTION: main 02-25 10:41:09.827: E/AndroidRuntime(18090): java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "atof" referenced by "libcocos2dcpp.so"... 02-25 10:41:09.827: E/AndroidRuntime(18090): at java.lang.Runtime.loadLibrary(Runtime.java:361)example 02-25 10:41:09.827: E/AndroidRuntime(18090): at java.lang.System.loadLibrary(System.java:525) 02-25 10:41:09.827: E/AndroidRuntime(18090): at com.example.game.game.(game.java:126) 02-25 10:41:09.827: E/AndroidRuntime(18090): at java.lang.Class.newInstanceImpl(Native Method) 02-25 10:41:09.827: E/AndroidRuntime(18090): at java.lang.Class.newInstance(Class.java:1130) 02-25 10:41:09.827: E/AndroidRuntime(18090): at android.app.Instrumentation.newActivity(Instrumentation.java:1061) 02-25 10:41:09.827: E/AndroidRuntime(18090): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2178) 02-25 10:41:09.827: E/AndroidRuntime(18090): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2311) 02-25 10:41:09.827: E/AndroidRuntime(18090): at android.app.ActivityThread.access$600(ActivityThread.java:149) 02-25 10:41:09.827: E/AndroidRuntime(18090): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293) 02-25 10:41:09.827: E/AndroidRuntime(18090): at android.os.Handler.dispatchMessage(Handler.java:99) 02-25 10:41:09.827: E/AndroidRuntime(18090): at android.os.Looper.loop(Looper.java:137) 02-25 10:41:09.827: E/AndroidRuntime(18090): at android.app.ActivityThread.main(ActivityThread.java:5214) 02-25 10:41:09.827: E/AndroidRuntime(18090): at java.lang.reflect.Method.invokeNative(Native Method) 02-25 10:41:09.827: E/AndroidRuntime(18090): at java.lang.reflect.Method.invoke(Method.java:525) 02-25 10:41:09.827: E/AndroidRuntime(18090): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739) 02-25 10:41:09.827: E/AndroidRuntime(18090): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555) 02-25 10:41:09.827: E/AndroidRuntime(18090): at dalvik.system.NativeStart.main(Native Method).

I am using cocos2d-x v2.2.6,Eclipse-Luna and android NDK r10d.

like image 549
Bhavuk Sehgal Avatar asked Feb 25 '15 05:02

Bhavuk Sehgal


3 Answers

Try adding

APP_PLATFORM := android-19 

as the first line in your Appication.mk

like image 93
Dmitry Avatar answered Nov 10 '22 08:11

Dmitry


Try using android NDK r9d.For cocos2dx ,Android NDK r9d is good to work.

like image 23
amisha.beladiya Avatar answered Nov 10 '22 10:11

amisha.beladiya


(I know this duplicates m0mus's earlier answer in the solution suggested, but I think the fuller explanation helps.)

Google have moved some of the C standard library functions like atof() from being inline functions in header files to normal functions. The latest NDKs will default to building a .so that is only compatible with the latest Android devices that have the atof() function in the device's standard C library (libc.so). This means if you run a library on an older device that has an older version of the C library, you will get an error loading the dll as the expected atof() function will not exist.

Have you tried setting this in your Application.mk:

APP_PLATFORM := android-9

This will cause the ndk compiler to build code compatible with older Android versions.

You can also try downgrading your NDK installation to version 10b (this version predates the change where atof was moved from inline to part of libc so avoids the problem entirely).

like image 1
JosephH Avatar answered Nov 10 '22 10:11

JosephH