Ao usar WebView.loadUrl(url);
no Android o em algumas versões do Android o aplicativo finaliza sozinho ("crash"), no caso a falha ocorreu na versões 6 e 7 do Android.
Notas:
- O Host GPU está ativado nos emuladores
- O problema ocorre em celulares também
A única maneira do problema não ocorre foi desativar a aceleração de hardware assim:
<activity android:hardwareAccelerated="false" />
Mas isto torna a performance do aplicativo pior, gostaria de usar a aceleração e "evitar" que o erro ocorra.
Eu adicionei as permissões (isto porque o minSdk é o 19):
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.guilherme.webviewexample">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
O build.gradle
está assim:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
...
E o código assim:
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myWebView = (WebView) findViewById(R.id.myWebView);
WebViewClient clientInterface = new WebViewClient();
WebView myWebView = (WebView) findViewById(R.id.myWebView);
WebSettings wbset = myWebView.getSettings();
wbset.setJavaScriptEnabled(true);
myWebView.setWebViewClient(clientInterface);
String url = "http://pt.stackoverflow.com";
myWebView.loadUrl(url);
}
Eu acredito que o erro seja este:
GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed to allocate storage for offscreen target depth buffer.
Segue o LOG no momento do crash:
11-10 10:52:13.779 22603-22603/com.example.guilherme.webviewexample I/chromium: [INFO:async_pixel_transfer_manager_android.cc(56)] Async pixel transfers not supported 11-10 10:52:13.809 22603-22603/com.example.guilherme.webviewexample E/chromium: [ERROR:gles2_cmd_decoder.cc(3389)] GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed to allocate storage for offscreen target depth buffer. 11-10 10:52:13.809 22603-22603/com.example.guilherme.webviewexample E/chromium: [ERROR:gles2_cmd_decoder.cc(2433)] Could not allocate offscreen buffer storage. 11-10 10:52:13.809 22603-22603/com.example.guilherme.webviewexample E/chromium: [ERROR:in_process_command_buffer.cc(465)] Could not initialize decoder. 11-10 10:52:13.809 22603-22603/com.example.guilherme.webviewexample A/libc: Fatal signal 11 (SIGSEGV) at 0x00000048 (code=1), thread 22603 (.webviewexample)