Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
286 views
in Technique[技术] by (71.8m points)

java - Supporting WebGL on Android 5's WebView

I have a web project (depends on WebGL) which works on computers, any browser. Now I am trying this project to be opened as an application on Android based mobile phones. I used WebView to accomplish this. My phone (Nexus 3) had Android 4.3 and as I learnt afterwards before Android 5, WebView component didn't support WebGL. With Android 5, WebView became an updatable independent component which depends on Chromium version 37 (can be updated) and started to support WebGL. So the error I was getting with Android 4.3 is expected.

After this I tried using another phone (Samsung galaxy S4 with Android 5 and Chrome version 43 on it). So then the application should have worked well, but still got error on WebView. I tried get.webgl.org still the same error:

Error constructing CesiumWidget.

Visit http://get.webgl.org to verify that your web browser and hardware support WebGL. Consider trying a different web browser or updating your video drivers.

Detailed error information is below:

RuntimeError: The browser supports WebGL, but initialization failed.

Error

at new RuntimeError (http://192.168.43.125:8090/TMAPW/lib/Cesium/Build/CesiumUnminified/Cesium.js:10657:19)
at new Context (http://192.168.43.125:8090/TMAPW/lib/Cesium/Build/CesiumUnminified/Cesium.js:96489:19)
at new Scene (http://192.168.43.125:8090/TMAPW/lib/Cesium/Build/CesiumUnminified/Cesium.js:120928:23)
at new CesiumWidget (http://192.168.43.125:8090/TMAPW/lib/Cesium/Build/CesiumUnminified/Cesium.js:130986:25)
at AMouseListener.Map2D.initWidget 

This still seemed like a configuration problem, so then I tried to open this on Chrome not on WebView yet still the same error. I enabled WebGL on Chrome following instuctions. `Firefox works fine though. I have three questions:

  1. Does there seem to be anything I am doing wrong, how can I fix it?

  2. Does Android still not support WebGL on WebView, isn't there any possible way to open WebGL dependent applications?

  3. Is there any other way to open a WebGL project as an application. (I have read about cordova and cocoon.js but not sure if it can be accomplished through these.) So if there is one which works fine I'd rather go directly for it.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Well I wanted to add this as an edit, but it wasn't accepted, so I added my findings as an answer:

I managed to make it work with CrossWalk on any device with Android 4+ on it and android webview with a sony xperia phone with android 5 on it. I wanted to add the things I've found:

If you want to use android webview, your device must have android 5+ and your device must not be on gpu_blacklist. There is no device list for gpu_blacklist on the net that I can find, but there is a way to understand that your device is in the gpu_blacklist or not. Open chrome, then type chrome://gpu, then look at reset notification strategy field. If it is 0x8252 then your device supports webgl, if it is 0x0000 then your device is in the blacklist. So with android 5+ and your device not being on the gpu_blacklist, you can use webgl with android webview.

If you want to use chrome instead of android webview even with a device which is on gpu_blacklist, you must use chrome version 37+. To check it, open chrome, type chrome://version. After that open chrome, type chrome://flags, in that page enable webgl and override software rendering list fields. With that you can use webgl even with devices that on the gpu_blacklist or with devices that has os below android 5 on them.

If your device can't provide above requirements, like mine, you can use CrossWalk it works. However, the documentation is not well organized and you can't find much information other than its own documentation, in case you have problems with it. The reason CrossWalk works is when you build apk file you can send command line arguments like --ignore-gru-blacklist. However as the documentation states if you use this on devices that are on the gpu_blacklist, your application or the whole device might froze.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...