JNI problems


#1

Hi,

It seems I continue my streak of problems getting native code to run on Android. I completed the SimpleGame tutorials, up until I added a new file the GameOverScene.cpp/.h files, build using msvc runs fine. i then got an error from ndk_build that I tracked down to the android.mk file and added GameOverScene.cpp to the LOCAL_SRC_Files… after that everything compiles perfectly using ./build_native.sh the problem comes up after I package the apk using Eclipse. The game will simple not start…

I have no idea how to fix this…

Here is the catlog:

12-16 03:13:26.354: D/dalvikvm(487): Trying to load lib /data/data/org.cocos2d.windroidgame/lib/libcocos2d.so 0x40513aa8
12-16 03:13:26.494: D/dalvikvm(487): Added shared lib /data/data/org.cocos2d.windroidgame/lib/libcocos2d.so 0x40513aa8
12-16 03:13:26.584: D/dalvikvm(487): Trying to load lib /data/data/org.cocos2d.windroidgame/lib/libcocosdenshion.so 0x40513aa8
12-16 03:13:26.584: D/dalvikvm(487): Added shared lib /data/data/org.cocos2d.windroidgame/lib/libcocosdenshion.so 0x40513aa8
12-16 03:13:26.614: D/dalvikvm(487): Trying to load lib /data/data/org.cocos2d.windroidgame/lib/libgame_logic.so 0x40513aa8
12-16 03:13:26.614: D/dalvikvm(487): Added shared lib /data/data/org.cocos2d.windroidgame/lib/libgame_logic.so 0x40513aa8
12-16 03:13:26.654: D/dalvikvm(487): No JNI_OnLoad found in /data/data/org.cocos2d.windroidgame/lib/libgame_logic.so 0x40513aa8, skipping init
12-16 03:13:26.654: D/dalvikvm(487): Trying to load lib /data/data/org.cocos2d.windroidgame/lib/libgame.so 0x40513aa8
12-16 03:13:26.663: D/dalvikvm(487): Added shared lib /data/data/org.cocos2d.windroidgame/lib/libgame.so 0x40513aa8
12-16 03:13:26.663: D/dalvikvm(487): No JNI_OnLoad found in /data/data/org.cocos2d.windroidgame/lib/libgame.so 0x40513aa8, skipping init
12-16 03:13:26.755: W/apk path(487): /data/app/org.cocos2d.windroidgame-1.apk
12-16 03:13:27.084: D/libEGL(487): egl.cfg not found, using default config
12-16 03:13:27.084: D/libEGL(487): loaded /system/lib/egl/libGLES_android.so
12-16 03:13:27.533: W/dalvikvm(487): JNI WARNING: 0x405181f0 is not a valid JNI reference
12-16 03:13:27.533: W/dalvikvm(487):              in Lorg/cocos2dx/lib/Cocos2dxRenderer;.nativeInit (II)V (CallStaticVoidMethodV)
12-16 03:13:27.543: I/dalvikvm(487): "GLThread 12" prio=5 tid=11 RUNNABLE
12-16 03:13:27.543: I/dalvikvm(487):   | group="main" sCount=0 dsCount=0 obj=0x405204a0 self=0x29e458
12-16 03:13:27.543: I/dalvikvm(487):   | sysTid=498 nice=0 sched=0/0 cgrp=default handle=2744472
12-16 03:13:27.543: I/dalvikvm(487):   | schedstat=( 110504501 360889866 29 )
12-16 03:13:27.543: I/dalvikvm(487):   at org.cocos2dx.lib.Cocos2dxRenderer.nativeInit(Native Method)
12-16 03:13:27.543: I/dalvikvm(487):   at org.cocos2dx.lib.Cocos2dxRenderer.onSurfaceCreated(Cocos2dxRenderer.java:40)
12-16 03:13:27.543: I/dalvikvm(487):   at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1348)
12-16 03:13:27.543: I/dalvikvm(487):   at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)
12-16 03:13:27.543: E/dalvikvm(487): VM aborting

I believe the problem is
12-16 03:13:27.533: W/dalvikvm(487): JNI WARNING: 0x405181f0 is not a valid JNI reference
12-16 03:13:27.533: W/dalvikvm(487): in Lorg/cocos2dx/lib/Cocos2dxRenderer;.nativeInit (II)V (CallStaticVoidMethodV)

but I don’t know how to fix it.


#2

Did you use create_android_project.bat to create android project?
What’s your android project looks like?


#3

hi, firstly, thanks for the amazing engine.

i encountered the same problem.

i create both android and xcode project, the core code was very simple, and worked in IOS perfectly, but was crashed on android, with the same error as Adam mentioned.
any suggestion?


#4

Hi Yes… the problem was because of the sound code, if you remove the sound code the problem goes away… there is a fix but I don’t recall it now.


#5

If you run on real phone.
I think it will be ok.
The bug is fixed in latest codes.


#6

i meet the same problem when i run my apk it crash no matter in emulator or real phone.

D/dalvikvm(1202): Added shared lib /data/data/com.youdong/lib/libgame_logic.so 0x41051f88