Android release build crash on lower versions

I am using cocos2dx 3.11.1 and Android NDK r10e.

I got a problem with the game building/running on Android 4.4 devices.

If I set target=android-21 or above in project.properties, i can build it successfully but the game crashes on Android 4.4 (it runs good on Android 5.0 or above). The crash was caused by:

dlopen failed: cannot locate symbol "rand" referenced by "libMyGame.so".

So I changed it totarget=android-19, now the build was not successful with link error:

...MyGame.cpp:97: error: undefined reference to "rand"

HOWEVER, if I build the project in debug mode (without “-m release”), it is all good no matter if it’s target=19 or target=24

BTW, I also tried NDK r11c. It is very similar but in the second scenario, the compile failed even earlier at CCConsole.cpp with all the function references to rand, srand, etc. And if I build it with target=android-19 without release mode, it also failed but the error is only the undefined reference to bzero in CCConsole.cpp.

I searched the forum and did not find a solution… Can someone please help?

OK, I cleared all the intermediate files and object files. It is working fine now with target=android-19. With android-24, the app still crashes on Android 4.4.4 though.

I’m facing same problem. I would like to support API level 14 at least, but there are crashes.

Sorry to hear that, but is the crash caused by “cannot locate symbol rand” as well?

I’ve never got a Android 4.0 device to test that, but maybe you can try to build the project with --ap=android-14 and see how it goes.

Thanks @na299

Yes, it was a rand problem, but targeting API 19 it’s ok for Android 5.1.1 on Nexus 5.

Actually I’m porting my game from v 3.7 to v3.11.1 and with v3.7 I was able to install on a Samsung GT-S5830C v2.3.6-GINGERBREAD. Now, I’m getting this:

 Trying to load lib /mnt/asec/com.test.test-1/lib/libcocos2dcpp.so 0x4051a720
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000
01-07 21:41:26.625 12208-12208/? I/DEBUG:  r0 83209c40  r1 83209c40  r2 bee6d3e4  r3 bee6d3e4
...

It’s similar to this issue: https://github.com/cocos2d/cocos2d-x/issues/15891

I don’t have an android 4.0 device to test, but I would like to know if my game won’t crash on these devices.

I’m using NDK-r10c.

@lfmn, Yes, targeting API 19 is OK for higher versions.

To be honest, I am very confused on the target-platform in cocos2dx. Although I can either specify the target-platform with arugments --ap=android-xx or set in project.properties under proj.android-studio/app directory, I don’t know exactly how much is affected by this. I mean, I can have different settings in the gradle script with targetSDK=24. So I am not very sure if the target-platform settings in cocos2dx only affects the build of library (libMyGame.so) and the gradle will take care of the build of application (the apk) or will it overrides the target in gradle. Maybe I just need to read more documentation about the build process of NDK development and/or the source code of the build scripts.

Nevertheless, back to the error you are facing, it looks like an error of dereferencing a nullptr. Maybe you can check the following:

  1. Make sure libcocos2dcpp.so is under the libs folder in the APK file. If not, you may need to change the lib name in AndroidManifest or check if the library in libs folder under your proj.android directory (I assume you are using Android Studio)…
  2. Check the logcat a few lines before the error you posted to see if there are any error messages like “cannot find xxx.png”, possible missing resources.

I’m very confused too with exactly same doubts. I’m using android studio and I realized that target of project.properties file is updated when I compile the project.

There is libcocos2dcpp.so file and I just see this messages:

onWindowFocusChanged(false)
07-08 00:11:32.063 1653-1653/? D/Launcher: setWallpaperDimension() called
07-08 00:11:32.063 1653-1653/? D/Launcher: USE_NON_SCROLLABLE_IMAGE_WALLPAPER is true
07-08 00:11:32.063 1653-1653/? D/Launcher: It's image wallpaper. suggestDesiredDimensions(-1,-1)

I’m testing to see if I could find a solution.