Android crash during the load of the native library after upgrading from 3.2 to 3.7

Hello folks.

Recently I updated from v3.2 to 3.7. There were no problems on iOS, only on Android (NDK10d).

The crash occurs during the load of the native library.

The log is not so much detailed and I don’t know how to start to fix it.

I know that the python script to compile for android was deprecated and now I use the cocos command to compile my eclipse project. Should I change something in somewhere to make my library load? Did something change on the JNI since v3.2? Did someone got this problem before?

Thanks in advance.

07-27 11:58:28.121: I/DEBUG(184): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
07-27 11:58:28.121: I/DEBUG(184): Build fingerprint: 'google/hammerhead/hammerhead:5.1.1/LMY48B/1863243:user/release-keys'
07-27 11:58:28.121: I/DEBUG(184): Revision: '11'
07-27 11:58:28.121: I/DEBUG(184): ABI: 'arm'
07-27 11:58:28.121: I/DEBUG(184): pid: 21663, tid: 21663, name: mplateProject32  >>> jp.co.awesome.TemplateProject32 <<<
07-27 11:58:28.122: I/DEBUG(184): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
07-27 11:58:28.131: I/DEBUG(184):     r0 b4878ac0  r1 3fffffff  r2 00000001  r3 b4878ac0
07-27 11:58:28.134: I/DEBUG(184):     r4 00000043  r5 b47fbae0  r6 00000000  r7 9dd59024
07-27 11:58:28.134: I/DEBUG(184):     r8 b4827800  r9 beedbe90  sl beedbe80  fp beedbcbc
07-27 11:58:28.135: I/DEBUG(184):     ip 9e34dbc4  sp beedbcb0  lr 9dd59050  pc 00000000  cpsr 600f0010
07-27 11:58:28.136: I/DEBUG(184): backtrace:
07-27 11:58:28.136: I/DEBUG(184):     #00 pc 00000000  <unknown>
07-27 11:58:28.136: I/DEBUG(184):     #01 pc 001fb04c  /data/app/jp.co.awesome.TemplateProject32-1/lib/arm/libcocos2dcpp.so (JNI_OnLoad+40)
07-27 11:58:28.136: I/DEBUG(184):     #02 pc 001e145b  /system/lib/libart.so (art::JavaVMExt::LoadNativeLibrary(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, art::Handle<art::mirror::ClassLoader>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*)+1614)
07-27 11:58:28.136: I/DEBUG(184):     #03 pc 00207b13  /system/lib/libart.so (art::Runtime_nativeLoad(_JNIEnv*, _jclass*, _jstring*, _jobject*, _jstring*)+514)
07-27 11:58:28.136: I/DEBUG(184):     #04 pc 000797f5  /data/dalvik-cache/arm/system@framework@boot.oat
1 Like

This is a very unhelpful stacktrace that Android produces but I suspect this is a missing entry point for the .so file.

Check main.cpp has an entry point like this:

// The signature of this method changed in v3.7
#if COCOS2D_VERSION <= 0x00030600
void cocos_android_app_init(JNIEnv* env, jobject thiz)
#else
void cocos_android_app_init(JNIEnv* env)
#endif
{
    AppDelegate *pAppDelegate = new AppDelegate();
}

and make sure you are actually building main.cpp (see Android.mk if you’re using the ant).

4 Likes

Thanks for the response.

This doesn’t seem to be the problem. The app can execute the line 77 on the file JniHelper.cpp

LOGD("JniHelper::setJavaVM(%p), pthread_self() = %ld", javaVM, thisthread);

Trace:

JniHelper::setJavaVM(0xb489d200), pthread_self() = -1224913940

So the main.cpp looks fine. But after this is the only one trace that is printed. No clue about what this means.

Any other ideas?

the interface of main function changed.
@Tengurek

I figured out the issue for one whole day.

Yeah, I notice that on the @trojanfoe 's post but… even with this interface, the problem is the same.

Did you change anything else?

After recompiling with Eclipse closed the error became less scary

07-28 14:27:26.636: I/DEBUG(184):     #04 pc 001b084c  /data/app/jp.co.awesome.TemplateProject32-2/lib/arm/libcocos2dcpp.so (AppDelegate::applicationDidFinishLaunching()+4212)
07-28 14:27:26.636: I/DEBUG(184):     #05 pc 001f3908  /data/app/jp.co.awesome.TemplateProject32-2/lib/arm/libcocos2dcpp.so (cocos2d::Application::run()+40)
07-28 14:27:26.636: I/DEBUG(184):     #06 pc 001fb11c  /data/app/jp.co.awesome.TemplateProject32-2/lib/arm/libcocos2dcpp.so (Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit+272)

Will keep investigating and updating my progress, thanks.

Thanks both, problem solved. Enjoying v3.7 :smile:
After recompiling everything with Eclipse closed, very important, don’t know exactly why, can run my games.
Also moved some of my own resources that weren’t in the right place and everything looks fine.

Thanks @trojanfoe that was what was breaking for me too, despite no error looking nearly like that. Cheers.

Who the hell though changing the signature of cocos_android_app_init is a good idea?

2 Likes

Thanks! Works for me!

This solution from @trojanfoe has really saved my day! You must be crazy to change this method signature without notice to those who want to upgrade an existing project …

This is the biggest problem in the cocos2d-x community: there is no established and stable way to upgrade an existing project!

And that’s why so many people are still using v2 =)

thanks trojanfoe . it is working for me.

I ran into this issue today upgrading cocos from an old beta 3.3 to 3.3.13 and put in logging statements until I found the crash using the dumped backtrace as a guide. Turned out it was due to the signature of cocos_android_app_init changing removing the second “jobject” parameter. Once I removed that from my main.cpp everything worked! It all made sense now why it was getting a nullptr dereferencing error as the stack frame was all messed up due to it thinking an extra parameter was pushed onto it.