Android integration

Android integration
0.0 0

#1

Hi, I’m using cocos2d-x-2.2.6 and my app crashes, when runnin on a device.
logcat points me on Cocos2dxRenderer.java file and it crashes in

@Override
public void onSurfaceCreated(final GL10 pGL10, final EGLConfig pEGLConfig) {
Cocos2dxRenderer.nativeInit(this.mScreenWidth, this.mScreenHeight);
this.mLastTickInNanoSeconds = System.nanoTime();
}

on calling Cocos2dxRenderer.nativeInit(this.mScreenWidth, this.mScreenHeight);

error is:
JNI DETECTED ERROR IN APPLICATION: JNI FindClass called with pending exception ‘java.lang.NoSuchMethodError’ thrown in void org.cocos2dx.lib.Cocos2dxRenderer.nativeInit(int, int):-2 in call to FindClass

What could be a reason of it?
Thanks.


JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal start byte 0xf0
#2

@zhangxm please help regarding this issue.


#3

@shauket can you make a test case to reproduce the issue since there is not problem with engine tests.


#4

Did you modify proj.android/jni/PROJECT_NAME/main.cpp, nativeInit() function is defined there.


#5

i see this function name in main.cpp does this matter with our code ?

Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit


#6

Did you modify it? Could you paste the contents of main.cpp? And does it crash at start up or crash after running for a while?


#7

it game create view

main.cpp fille

#include “AppDelegate.h”
#include “cocos2d.h”
#include “CCEventType.h”
#include “platform/android/jni/JniHelper.h”
#include <jni.h>
#include <android/log.h>

#define LOG_TAG “main”
#define LOGD(…) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,VA_ARGS)

using namespace cocos2d;

extern “C”
{

jint JNI_OnLoad(JavaVM *vm, void *reserved)
{
JniHelper::setJavaVM(vm);

return JNI_VERSION_1_4;

}

void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h)
{
if (!CCDirector::sharedDirector()->getOpenGLView())
{
CCEGLView *view = CCEGLView::sharedOpenGLView();
view->setFrameSize(w, h);

    AppDelegate *pAppDelegate = new AppDelegate();
    CCApplication::sharedApplication()->run();
}
else
{
    ccGLInvalidateStateCache();
    CCShaderCache::sharedShaderCache()->reloadDefaultShaders();
    ccDrawInit();
    CCTextureCache::reloadAllTextures();
    CCNotificationCenter::sharedNotificationCenter()->postNotification(EVENT_COME_TO_FOREGROUND, NULL);
    CCDirector::sharedDirector()->setGLDefaultValues(); 
}

}

}


#8

@shauket the codes in main.cpp seems good, did you modify Cocos2dxRenderer.java? Is private static native void nativeInit(final int pWidth, final int pHeight); in Cocos2dxRenderer.java?


#9

no i did not changed this method.


#10

I have not idea. The error means it can not found the nativeInit(), but it is implemented in main.cpp. The only possibility is that, main.cpp is not compiled? But i think it is not possible.

Could you please run the following command to check if nativeInit is included in libhellocpp.so like this

/Users/minggo/bin/android/android-ndk-r11c/toolchains/x86_64-4.9/prebuilt/darwin-x86_64/bin/x86_64-linux-android-nm --dynamic ./libhellocpp.so | grep "nativeInit"
000c5099 T Java_org_cocos2dx_lib_Cocos2dxBitmap_nativeInitBitmapDC
0008ad25 T Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit

You should use change the file path to your local path.


#11

I am trying to run this command but its not working… I am having similar kind of issue

JNI DETECTED ERROR IN APPLICATION:jmethodID was NULL
in call to CallObjectMethodV
from java.lang.String java.lang.Runtime.nativeLoad(java.lang.String, java.lang.ClassLoader, java.lang.String)

Thanks


#12

Is .so loaded correctly?