简体   繁体   English

在Android 5的WebView上支持WebGL

[英]Supporting WebGL on Android 5's WebView

I have a web project (depends on WebGL) which works on computers, any browser. 我有一个Web项目(取决于WebGL),可在计算机和任何浏览器上工作。 Now I am trying this project to be opened as an application on Android based mobile phones. 现在,我正在尝试将该项目作为基于Android手机的应用程序打开。 I used WebView to accomplish this. 我使用WebView来完成此任务。 My phone (Nexus 3) had Android 4.3 and as I learnt afterwards before Android 5, WebView component didn't support WebGL. 我的手机(Nexus 3)安装了Android 4.3,随后我在Android 5之前了解到,WebView组件不支持WebGL。 With Android 5, WebView became an updatable independent component which depends on Chromium version 37 (can be updated) and started to support WebGL. 在Android 5中,WebView成为依赖Chromium 37版(可以更新)的可更新独立组件,并开始支持WebGL。 So the error I was getting with Android 4.3 is expected. 因此,我在使用Android 4.3时遇到的错误是可以预期的。

After this I tried using another phone (Samsung galaxy S4 with Android 5 and Chrome version 43 on it). 之后,我尝试使用另一部手机(具有Android 5和Chrome 43版的三星银河S4)。 So then the application should have worked well, but still got error on WebView. 因此,该应用程序本应该运行良好,但在WebView上仍然出现错误。 I tried get.webgl.org still the same error: 我尝试过get.webgl.org仍然是相同的错误:

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. 这似乎仍然是配置问题,因此我尝试在Chrome而不是WebView上打开它,但仍然是相同的错误。 I enabled WebGL on Chrome following instuctions. 我根据指示在Chrome上启用了WebGL。 `Firefox works fine though. `Firefox可以正常工作。 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? Android是否仍不支持WebView上的WebGL,是否没有任何可能的方法来打开依赖WebGL的应用程序?

  3. Is there any other way to open a WebGL project as an application. 还有其他方法可以将WebGL项目作为应用程序打开。 (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. (我已经阅读了关于cordovacocoon.js但不确定是否可以通过这些完成。)因此,如果有一种可以正常工作,我宁愿直接使用它。

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. 我设法使其在任何装有Android 4+设备上与CrossWalk一起工作, CrossWalk在其上装有带android 5sony xperia手机的android webview上运行。 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 . 如果要使用android webview ,则设备必须具有android 5+并且设备不得位于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. 我在网上找不到gpu_blacklist设备列表,但是有一种方法可以了解您的设备是否在gpu_blacklist Open chrome, then type chrome://gpu , then look at reset notification strategy field . 打开chrome,然后输入chrome://gpu ,然后查看reset notification strategy field If it is 0x8252 then your device supports webgl , if it is 0x0000 then your device is in the blacklist. 如果为0x8252则您的设备支持webgl ;如果为0x0000则您的设备位于黑名单中。 So with android 5+ and your device not being on the gpu_blacklist , you can use webgl with android webview . 因此,在android 5+和您的设备不在gpu_blacklist上的gpu_blacklist ,您可以将webglandroid 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+. 如果即使在gpu_blacklist上的设备上gpu_blacklist使用chrome而不是android webview ,则必须使用chrome版本37+。 To check it, open chrome, type chrome://version . 要检查它,请打开chrome,输入chrome://version After that open chrome, type chrome://flags , in that page enable webgl and override software rendering list fields. 打开chrome后,在该页面中键入chrome://flags ,启用webgloverride software rendering list字段。 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. 有了它,您甚至可以在gpu_blacklist上的gpu_blacklist或操作系统低于android 5设备上使用webgl

If your device can't provide above requirements, like mine, you can use CrossWalk it works. 如果您的设备无法像我的设备一样满足上述要求,则可以使用CrossWalk 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 . CrossWalk起作用的原因是,当您生成apk文件时,您可以发送--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. 但是,如文档所述,如果您在gpu_blacklist上的设备上使用此功能,则您的应用程序或整个设备可能会冻结。

I suggest you try CrossWalk, based on Chromium/blink 我建议您尝试基于Chromium / blink的CrossWalk

https://crosswalk-project.org/documentation/samples/webgl.html https://crosswalk-project.org/documentation/samples/webgl.html

Except Samsung s4 with Android 5.0.1 , rest all devices return webgl true. 除带有Android 5.0.1的Samsung s4之外,其余所有设备均返回webgl true。

  • | | Nexus 9 | Nexus 9 | Android 5.0 | Android 5.0 | webgl works | webgl作品|
  • | | Nexus 6 | Nexus 6 | 5.1.1 | 5.1.1 | webgl works | webgl作品|
  • | | htc | htc | 4.4.4 | 4.4.4 | webgl works | webgl作品|
  • | | samsung galaxy note 4 | 三星银河注4 | 5.0.1 | 5.0.1 | webgl works | webgl作品|
  • | | samsung s4 | 三星s4 | 5.0.1 | 5.0.1 | webgl doesn't work | webgl不起作用|
  • | | samsung s5 | 三星s5 | 6.0 | 6.0 | webgl works | webgl作品|
  • | | Nexus 5 | Nexus 5 | 6.0 | 6.0 | webgl works| webgl运作|
  • | | MotoX | MotoX | 6.0 | 6.0 | webgl works | webgl作品|

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM