[SOLVED] Android fatal exception running default application

Cocos2d-x version is 3.9 , 3.8.1 or git current
System
Mac OS X 10.11.2 El Capitan
with Android SDK installed with Android Studio (December 2015)
NDK_ROOT=/Volumes/Home/Library/Android/android-ndk-r10e
ANDROID_SDK_ROOT=/Volumes/Home/Library/Android/sdk
ANT_ROOT=/usr/local/Cellar/ant/1.9.6/bin

device is Samsumg Galaxy Tab4

Did a standard installation

cocos new mygame -p com.your_company.mygame -l cpp
cd mygame

running from the command line with ant

cocos run -p android --ap android-21

app builds, installs on device, when run a message dialog shows

“Unfortunatley, mygame has stopped”

when building with gradle from within Android Studio

the logcat shows

FATAL EXCEPTION: main
Process: com.your_company.mygame, PID: 26880
java.lang.UnsatisfiedLinkError: Couldn’t load cocos2dcpp from loader dalvik.system.PathClassLoader[DexPathList[[zip file “/data/app/com.your_company.mygame-1.apk”],nativeLibraryDirectories=[/data/app-lib/com.your_company.mygame-1, /vendor/lib, /system/lib]]]: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:358)
at java.lang.System.loadLibrary(System.java:526)
at org.cocos2dx.lib.Cocos2dxActivity.onLoadNativeLibraries(Cocos2dxActivity.java:248)
at org.cocos2dx.lib.Cocos2dxActivity.onCreate(Cocos2dxActivity.java:263)
at android.app.Activity.performCreate(Activity.java:5451)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
at android.app.ActivityThread.access$900(ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)

running again from start, this time with API level 22 (API 23 is broken for Cocos2d-x 3.9)

$ cocos new mygame -p com.your_company.mygame -l cpp
$ cocos run -p android --ap android-22

same dialog box error on device

$ adb logcat -d > logcat.txt

below are parts of logcat.txt that seem relevant

it seems a link issue

cannot locate symbol “srand” referenced by “libcocos2dcpp.so”.

therefore a cocos2d-x bug in the android makefiles

W/ActivityManager( 570): Permission Denial: getCurrentUser() from pid=4582, uid=10158 requires android.permission.INTERACT_ACROSS_USERS
I/MultiUserPreferences( 1199): openUserData
I/MultiUserPreferences( 1199): validate
I/ActivityManager( 570): Killing 3937:com.sec.kidsplat.installer/u0a129 (adj 15): bgCount ##33
I/MultiUserPreferences( 1199): writeElement
I/MultiUserPreferences( 1199): commit
D/STATUSBAR-IconMerger( 741): checkOverflow(992), More:false, Req:false Child:1
D/BatteryMeterView( 741): onDraw batteryColor : -1
W/ActivityManager( 570): Permission Denial: getCurrentUser() from pid=4582, uid=10158 requires android.permission.INTERACT_ACROSS_USERS
D/dalvikvm( 4582): Trying to load lib /data/app-lib/com.your_company.mygame-1/libcocos2dcpp.so 0x423e0490
E/dalvikvm( 4582): dlopen("/data/app-lib/com.your_company.mygame-1/libcocos2dcpp.so") failed: dlopen failed: cannot locate symbol “srand” referenced by “libcocos2dcpp.so”…
D/AndroidRuntime( 4582): Shutting down VM
W/dalvikvm( 4582): threadid=1: thread exiting with uncaught exception (group=0x41d3ac08)
E/AndroidRuntime( 4582): FATAL EXCEPTION: main
E/AndroidRuntime( 4582): Process: com.your_company.mygame, PID: 4582
E/AndroidRuntime( 4582): java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol “srand” referenced by “libcocos2dcpp.so”…
E/AndroidRuntime( 4582): at java.lang.Runtime.loadLibrary(Runtime.java:364)

Andoid development in itself is a challenge, but with Cocos2d-x even more

What’s the point of doing a rushed Cocos2d-x release every 2 months or so, if when trying a simple generated framework does not even run ?

It seems that there is not even an attempt to do some minimal testing ?

Come on, doing a sample auto generated project on the latest SDK should work …

1 Like

The solution for this was to make the build use SDK android-19

  1. remove all SDKs from the system higher that android-19
  2. do
    $ cocos run -p android -j 4

without any API level specified

it seems that the build detects the latest available SDK if none is specified and because with cocos2d-x 3.9
with

  1. android-23 we get a compilation error
  2. android-22, 21 we get either linking errors or runtime errors

so it worked with android-19

@PedroVicente Thanks a lot for that information! Do you know if this is also needed when using the latest cocos2d-x 3.10?

And, don’t you run into any issues with not supported items in your AndroidManifest when using SDK android-19? For example often some values of android:configChanges are not supported in that SDK yet. What do you do in that case?

Example:

@PedroVicente I am just upgrading to 3.10 from 3.3 and not facing any srand or library loading issue. My minSdkVersion is 15 and target API is 21.

@jarsj The crashes will not appear on all Android devices. On my test devices it worked fine, but at lots of my app users not.

@netunlimited can you mention some devices where it happens. Our QA has pretty much all popular android devices (atleast in India).

@jarsj Unfortunately I’m having trouble finding back that info in GooglePlay’s crashes dashboard. It was a while back and it doesn’t have any search option there.