Cocos2d-x v3.7 works with Android 5.0.2 but crashes with 4.4.4?

I’m using Android SDK 22, NDK r10c, and cocos2d-x v 3.7 (C++)

My app compiles and runs on Android 5.0.2, but seems to crash immediately on 4.4.4 (with the message, “Unfortunately has stopped working”.

I don’t use any special libraries (AdMob etc), so how can I determine why it is crashing on 4.4.4 ? I can’t debug because I don’t have eclipse. I use only the command line.

I am also having this issue. I’m thinking I might have to go back to 3.6 for now.

But all the Cpp-tests work when I do:

python android-build.py -p 22 cpp-tests

adb install CppTests-debug.apk

The device I am testing on is running 4.4.4
So why would my app crash ?

I have run 3.7 on a Nexus 7 Razor 4.4.4 without issue.

To debug the Android crash by using android tools:

Add the path to the Android platform-tools in your Android SDK folder:

On Mac add this line to your .bash_profile and restart Terminal:

 export PATH=/your-path-to-sdk-android-sdk/android-sdk-macosx/platform-tools:$PATH

On Windows goto Control Panel -> System and Security -> System -> Environment Variable and add the path to the platform-tools folder.

Readup about how to use adb logcat to debug an android app.
http://developer.android.com/tools/help/logcat.html
The adb tool can do all sorts of useful things.

In a Terminal on Mac or Cmd on Windows, run adb logcat

On Mac you can press CMD-K to delete the previous adb logcat output.

Run the app via console using cocos run -p android from within your game folder.

Analyze the adb logcat debug log output to see why your app is crashing.

2 Likes

Thanks Heyalda! I have found the problem but don’t know how to solve it yet.

D/dalvikvm(11761): Trying to load lib /data/app-lib/com.chumbyfuzz.spacegame-1/libcocos2dcpp.so 0x41975510
E/dalvikvm(11761): dlopen("/data/app-lib/com.chumbyfuzz.spacegame-1/libcocos2dcpp.so") failed: dlopen failed: cannot locate symbol “srand” referenced by “libcocos2dcpp.so”…
D/AndroidRuntime(11761): Shutting down VM
W/dalvikvm(11761): threadid=1: thread exiting with uncaught exception (group=0x416a1d40)
E/AndroidRuntime(11761): FATAL EXCEPTION: main
E/AndroidRuntime(11761): Process: com.chumbyfuzz.spacegame, PID: 11761
E/AndroidRuntime(11761): java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol “srand” referenced by “libcocos2dcpp.so”…
E/AndroidRuntime(11761): at java.lang.Runtime.loadLibrary(Runtime.java:364)
E/AndroidRuntime(11761): at java.lang.System.loadLibrary(System.java:526)
E/AndroidRuntime(11761): at org.cocos2dx.lib.Cocos2dxActivity.onLoadNativeLibraries(Cocos2dxActivity.java:207)
E/AndroidRuntime(11761): at org.cocos2dx.lib.Cocos2dxActivity.onCreate(Cocos2dxActivity.java:222)
E/AndroidRuntime(11761): at android.app.Activity.performCreate(Activity.java:5248)
E/AndroidRuntime(11761): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
E/AndroidRuntime(11761): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
E/AndroidRuntime(11761): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
E/AndroidRuntime(11761): at android.app.ActivityThread.access$800(ActivityThread.java:139)
E/AndroidRuntime(11761): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
E/AndroidRuntime(11761): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime(11761): at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime(11761): at android.app.ActivityThread.main(ActivityThread.java:5086)
E/AndroidRuntime(11761): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(11761): at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime(11761): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
E/AndroidRuntime(11761): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
E/AndroidRuntime(11761): at dalvik.system.NativeStart.main(Native Method)

Any idea how to fix this ? Based on googling it seems the problem is because I am using android-22 platform, which is higher than the api level of android 4.4.4 (my device). Other people have used android-19 to solve this.

But I don’t know how to do this. If I do:

cocos run -p android --ap android-10

Then it says that:

The Android-platform of project ‘/Users/chumbyfuzz/Documents/Projects/spacegame/proj.android’ should be equal/larger than 22, but 10 is specified.

So how can I force it to use a lower platform ?

What NDK are you using? NDK >= android-ndk-r10d?

I’m installing 4.4.4 on my Nexus 7 right now to do a test with 3.7 and ndk-r10d to see if I have any issues with a game I am about to publish.

I am using NDK = r10c

This is just my noobtastic googling:

Trojan Foe said:

This relates to an issue where some functions, including atof() and srand(), were static inline before android-21 but have been moved into the library .so file since then. If you compile your app against the android-21 and run it on a pre-android-21 device you will get this error.

I would imagine the answer is to ensure your app does not run on a version of android less than the one it was compiled against.

So I guess the issue is the Android SDK you are using. Not the NDK. I just updated my project.properties, AndroidManifest.xml and its compiling now!

Here are the changes I made:
In project.properties:

target=android-10

In AndroidManifest.xml:

<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="10" />

In Application.mk

APP_PLATFORM := android-10

Its working now! Running on 4.4.4! Thanks for your help! :stuck_out_tongue_closed_eyes: XD Couldn’t have done it without you, and now I finally understand how this works. Having not built any android apps before I didn’t understand how all the pieces fit together till now.

But the key question is, what should the target sdk be ?

  • As I do not have all the devices to test any version prior to 4.4.4, how can I verify my app will work ?

Or should I use platform android-10, but set the minds and targetsdk to android-19 ? Does that make sense ?

Or should I just use platform android-19 ? It seems like a waste, since a large number of users use Jellybean (API 16 and above).

Yep, just tested mine too with 4.4.4 and it works ok.
I too have similar settings that you have, but I use 13 as my version.

But for project.properties, I think that is generated by the android tools that the cocos console executes, so changes there wont make an impact.

I don’t have a setting for APP_PLATFORM in Application.mk.

But I do have the min and target sdk set in AndroidManifest.xml.
If you dont set the target, then it defaults to the minimum sdk that is defined.
Details about what to set that here: http://developer.android.com/guide/topics/manifest/uses-sdk-element.html

For other folks, they might need to verify the sdk versions that they have installed. This can be done from the command line:

android update sdk

The android command line tool is located in the tools folder in the android sdk folder.
Not certain if that matters, but I have API-22, 21 and 13 installed for mine to work ok. Haven’t tested it with just having 22 installed.

Regarding the SDK version number to support…
I’ve had about 900,000 downloads of my Android games in the past year and this is what my stats look like for one of my games that has about 225,000 downloads. The other games have similar distributions for Android version.

So I am missing out on a little bit of the available market by targeting >= API-13 (Android 3.2), but not much. And my games would probably run like crap on the older devices that ar running 2.x anyway, so no big deal.

So the devices that are less than API-16 (Android 4.1) make up about 25% of the market (at least for racing games).

I dont see any reason not to add in at least API-15 (4.0.3) which gives you an extra 10% of the market that you wouldn’t get if you chose API-16 as a min.

But these stats might vary by genre.

Testing on Android is tough.

There are services you can pay if you really want to be thorough, but I have not tried them.

I buy Nexus devices since Google makes it easy to quickly re-image the OS: https://developers.google.com/android/nexus/images?hl=en

I also bought some Samsung phones and and cheap Asus and other brand tablets.

Now that Android supports 64-bit, I had to buy a Nexus 9 with a 64-bit cpu.

But even with a simple testing setup of several devices it seems to have been effective enough for the games I have published.

That was a great post. I’ve been looking at the dashboard: https://developer.android.com/about/dashboards/index.html

It concurs with your suggestion. If you support API-16, then you should be able to support 90% of the market.

If you change the platform to use android-22, and then run it on your 4.4.4 device, then I am pretty sure it will crash - you have probably already configured it correctly to use 13, and on devices running higher than 13, the OS is supposed to use compatibility mode.

I think your settings may be slightly different, since I did not set the targetSdk before, and it was compiling with 22, even though my minSDK was 9. By quickly googling the other posts I just tried the changes I made to see if it would work. Some of the settings may not be necessary, so I will try removing / changing some of them and seeing what happens.

EDIT: Just to clarify, when running on any OS higher than your targetSDK, the OS is supposed to run the app in compatibility mode. The reason I was having my crash was because of the reason Trojanfoe mentioned (Android removing some code from libcocos2d.so in Lollipop). By using an API <=19, on lollipop it used compatibility mode, and it worked. But the reverse (using API = 22), caused the crash because of the missing code when running on 19.

I’ve tried android-10, 18 and 19 and nothing stops it from crashing on earlier than v5.0.

Does anyone have a different solution? Earliest I’m looking to support is Lollipop.

Hey brah. it works fine. I’m using 4.4.4.

I’m a noob like you, but due to my noobtastic research efforts, and the noobalicious support by Heyalda, I figured it out and described it above. Did you read my posts carefully?

I’m using Android-10, and it works great to 4.4.4 and 5.0.2

I was on 3.6, I’m going to upgrade to cocos 3.7 to see if that changes anything.

To anyone doing the same thing, and getting all kinds of weird errors on compile and linking through cocos, delete both the proj.android/bin and proj.android/obj folder. It’ll make sure you’ve got a clean set of files to deal with.

I nuked my proj.android/bin and proj.android/obj folder after upgrading to cocos3.7, and I got it to run on android 4.3.1 thanks to your tip for android 10.

But if you really want to be noobtastic, you’ve gotta understand why it works. XD (read above posts by yours truly). You should also understand how android runs apps based on your minimumsdk, targetsdk settings and the platform you compile agains.

It seems like there is an issue with 3.6 or it was in the bin or obj folder. Your android 10 thing was the key to fixing it after the clean up.

I still don’t understand why it does work though, android 10 is the default. If you check the log of cocos compile it defaults to 10 as a fallback.

Trojan Foes comment which I quoted above explains everything brahski!