Crash on Android 4.2

I’m having an isssue running on android 4.2. Any thoughts? I’m building against android-19/android-ndk-r10e/ cocos 3.7 (upgrading is currently not practical).

********** Crash dump: **********
Build fingerprint: 'samsung/espressowifiue/espressowifi:4.2.2/JDQ39/P3113UEUCMK3:user/release-keys'
pid: 29549, tid: 29549, name: kmediagames.tos  >>> com.game.tos <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000
Stack frame #00  pc 00be71c0  /data/app-lib/com.game.tos-1/libcocos2dcpp.so (_JavaVM::GetEnv(void**, int)+28)
Stack frame #01  pc 00be7980  /data/app-lib/com.game.tos-1/libcocos2dcpp.so (cocos2d::JniHelper::cacheEnv(_JavaVM*)+68)
Stack frame #02  pc 00be7b1c  /data/app-lib/com.game.tos-1/libcocos2dcpp.so (cocos2d::JniHelper::getEnv()+72)
Stack frame #03  pc 00be7cfc  /data/app-lib/com.game.tos-1/libcocos2dcpp.so (cocos2d::JniHelper::getStaticMethodInfo(cocos2d::JniMethodInfo_&, char const*, char const*, char const*)+72)
Stack frame #04  pc 00beb838  /data/app-lib/com.game.tos-1/libcocos2dcpp.so (cocosplay::lazyInit()+96)
Stack frame #05  pc 00bdf5fc  /data/app-lib/com.game.tos-1/libcocos2dcpp.so (cocos2d::FileUtilsAndroid::init()+40)
Stack frame #06  pc 00bdf450  /data/app-lib/com.game.tos-1/libcocos2dcpp.so (cocos2d::FileUtils::getInstance()+108)

It’s hard to say:

  1. Did it crash right on startup?
  2. Is it only happening on Android 4.2? Have you tried other devices or simulator?
  3. Is it working on other platforms?
  4. Do you, by chance, save or read some files outside app directory? (sdcard for example). If so, you should check if it has enough permissions.
  1. Yes, it’s crashing when FileUtilsAndroid creates it’s underlying instance, so it is getting to the invocation of my code.
  2. An older build worked on Android 5. Not a helpful response, I know. I had other issues w/ simulators so I’m limited on my testing devices.
  3. Builds and works fine on iOS
  4. No.

My gut is telling me something is screwed up somewhere that’s causing the JavaVM instance in JniHelper to be null. since cacheEnv(jvm) calls jvm->getEnv() without checking jvm

This leads me to the following in my logcat

No JNI_OnLoad found in /data/app-lib/com.game.tos-1/libc++_shared.so 0x416ee538, skipping init

I think i’m on the right track here but am missing something.

Thanks

Actually I would assume it would be normal to not find JNI_OnLoad in libc++shared, so that may not be related at all.

I have found the cause of this issue. Wanted to follow up here incase anyone else runs into it.

This comes from accessing the FileUtils() class during the initialization of a static variable. Static variables as we all know are initialized VERY early. In this case initialized before JNI_OnLoad has a chance to set the JVM reference, which FileUtilsAndroid depends on.

Rick.