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

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


Hi guys, I involved UIWebView code from this page( , 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.
web = new LayerWebView();
float rate=getCC_DESIGN_W()/size.width;
web->setSize(size.width, size.height-bgButton->getContentSize().height/rate);

*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.*
//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”);
CCLog(“jni:got it”);
jstring jstrRe = stoJstring(methodInfo.env, url);
void init{
JniMethodInfo methodInfo;
if V“))
CCLog(”jni:not exsit“);
CCLog(”jni:got it");
methodInfo.env~~>CallVoidMethod(methodInfo.classID, methodInfo.methodID);

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: 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 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/ 0x40514900
11-17 16:33:08.859: D/dalvikvm(23124): Added shared lib /data/data/net.ssk.ygec/lib/ 0x40514900
11-17 16:33:08.869: D/dalvikvm: No JNI_OnLoad found in /data/data/net.ssk.ygec/lib/ 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.