Issue about Webview in android after built native code from cocos2d-2.0-x-2.0.4.

Hi guys, I involved UIWebView code from this page( http://www.cocos2d-x.org/boards/6/topics/4450?r=9923#message-9923) , it’s working well on IOS, now I want transfer it to android, the process of build native is ok, but I cannot got any UI in android and have not got any error information also, like freeze.

Would you please give me some advices about my issue? Did I use it like the following code is right? Many thanks.

1. Used it as following code.
@
#if (CC_TARGET_PLATFORM CC_PLATFORM_ANDROID)
init();
updateURL(“close”);
#else
web = new LayerWebView();
web->init();
web->updateURL(url.c_str());
float rate=getCC_DESIGN_W()/size.width;
web->setSize(size.width, size.height-bgButton->getContentSize().height/rate);
addChild(web,2);
#endif
@

*2. Added two function in your code as following code.*
@
void updateURL(const char * url);
void setSize(float width,float height);
@

*3. Defined for android.*
@
#if (CC_TARGET_PLATFORM CC_PLATFORM_ANDROID)
//char* to jstring
jstring stoJstring(JNIEnv* env, const char* pat){
jclass strClass = env~~>FindClass;
jmethodID ctorID = env~~>GetMethodID(strClass, “”, “([BLjava/lang/String;)V”);
jbyteArray bytes = env~~>NewByteArray);
env~~>SetByteArrayRegion(bytes, 0, strlen(pat), (jbyte*)pat);
jstring encoding = env~~>NewStringUTF;
return env~~>NewObject(strClass, ctorID, bytes, encoding);
}

void updateURL(const char * url){
JniMethodInfo methodInfo;
if (!JniHelper::getStaticMethodInfo(methodInfo, “net/ssk/ygec/WebKit”, “updateURL”, “(Ljava/lang/String)V”))
{
CCLog(“jni:not exsit”);
}else{
CCLog(“jni:got it”);
jstring jstrRe = stoJstring(methodInfo.env, url);
methodInfo.env~~>CallVoidMethod;
methodInfo.env~~>DeleteLocalRef(jstrRe);
methodInfo.env~~>DeleteLocalRef;
}
}
void init{
JniMethodInfo methodInfo;
if V“))
{
CCLog(”jni:not exsit“);
}else{
CCLog(”jni:got it");
methodInfo.env~~>CallVoidMethod(methodInfo.classID, methodInfo.methodID);
methodInfo.env->DeleteLocalRef(methodInfo.classID);
}
}
#endif
@

Thanks again

Did you check if pointers are not NULL? I don’t see your JVM in the code, you cannot take it from one part in the code and re-use in other, you must take it every function is going to use it.

You have an example to use JNI HERE: https://github.com/Piperoman/CCSocialNetwork/blob/master/GetSocial/Classes/JNICalls/InterfaceJNI.cpp Maybe it helps you.

Definitely, it’s helpful, let me following your link to test again , thanks.

Follow your suggestion,try again, it’s looks the same, have not got UI, please kindly find information below! Thanks.

11-17 16:33:07.879: I/AlarmManager(124): wakelock acquire, uid:1000 at elapsed real time: 888827572
11-17 16:33:07.879: I/AlarmManager(124): wakelock release, uid:1000 at elapsed real time: 888827580
11-17 16:33:08.529: I/ActivityManager(124): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=net.shishangkong.ygec/.YGEC bnds=[13,76][133,211] } from pid 22225
11-17 16:33:08.579: D/PhoneWindow(22225): couldn’t save which view has focus because the focused view com.android.launcher2.CellScreen@4054d0c8 has no id.
11-17 16:33:08.589: I/ActivityManager(124): Start proc net.shishangkong.ygec for activity net.ssk.ygec/.YGEC: pid=23124 uid=10099 gids={3003}
11-17 16:33:08.629: I/WindowManager(124): Setting rotation to 1, animFlags=1
11-17 16:33:08.629: E/jdwp(23124): Failed sending reply to debugger: Broken pipe
11-17 16:33:08.629: D/dalvikvm(23124): Debugger has detached; object registry had 1 entries
11-17 16:33:08.649: I/ActivityManager(124): Config changed: { scale=1.0 fontSize=2 themeChanged=0 themeChangedFlags=0 imsi=460/0 loc=zh_CN touch=3 keys=1/1/2 nav=1/1 orien=2 layout=34 uiMode=17 seq=201}
11-17 16:33:08.819: D/dalvikvm(23124): Trying to load lib /data/data/net.ssk.ygec/lib/libgame.so 0x40514900
11-17 16:33:08.859: D/dalvikvm(23124): Added shared lib /data/data/net.ssk.ygec/lib/libgame.so 0x40514900
11-17 16:33:08.869: D/dalvikvm: No JNI_OnLoad found in /data/data/net.ssk.ygec/lib/libgame.so 0x40514900, skipping init
11-17 16:33:08.909: D/dalvikvm(23124): GC_EXTERNAL_ALLOC freed 54K, 49% free 2763K/5379K, external 0K/0K, paused 31ms
11-17 16:33:13.659: W/WindowManager: App freeze timeout expired.
11-17 16:33:13.659: W/WindowManager: Force clearing freeze: AppWindowToken{40c99090 token=HistoryRecord{40856738 net.ssk.ygec/.YGEC}}

No JNI_OnLoad found in; is not essential, you code must run without it. IT appear like in some zone, your code stay waiting for something and you get an App freeze timeout. What functions are you calling before your app is freeze? Put more CCLogs to check what steps work, and when it stop.

The issue has been resolved, I forgot pushing the UI operation into android message loop, so it crashed.

Pipero Man, Many thanks your help.