非常简单的 WebView 在 API 23 模拟器下崩溃
Very simple WebView crashes under API 23 Emulator
我刚刚在我的机器上创建了一个 API 23 模拟器:
- HAXM:v1.4,分配 1GB RAM
- AVD 基础:Nexus 4
- RAM:768MB,第二次尝试 896MB
- 堆:64 MB
- GPU 加速:无
我用我自己的几个应用程序尝试成功。但是每次我尝试将 WebView
用作 UI 的应用程序时,应用程序都会以这种方式崩溃:
此 logcat 的前三行仅与我的应用程序相关(以蓝色突出显示)。所有其他行都没有在 LogCat 的 'Application' 列中提及我的应用程序包的名称,但在消息中间有一行(用蓝色圈出)。
我可以将 HTML 代码加载到 WebView
中。崩溃发生在 setContentView(theWebView)
时间:
public class MyActivity extends Activity {
private WebView mWebview = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mWebview = new WebView(this);
mWebview.loadDataWithBaseURL("file:///android_asset/", HTML_CODE, "text/html", "UTF-8", null);
setContentView(mWebview); // THIS IS WHERE THE CRASH OCCURS
}
[...]
使用或不使用 runOnUiThread()
到 运行 mWebview.loadDataWithBaseURL()
产生完全相同的结果,这是预期的,因为 onCreate()
实际上是在 UI 线程上.
我使用的 html 代码没有任何改变。在上面的例子中,HTML_CODE
变量包含这个:
<html>
<head></head>
<body>
<h1>Hello</h1>
<p>Hello world!</p>
</body>
</html>
应用程序 运行 非常完美,即使在所有 API 我尝试了 17 和 19 种设备和模拟器。这就是我不解的地方。不过,我没有机会尝试使用实际的 Android 6.0 (API 23) 设备。
编辑
我刚刚:
- 从 Eclipse 迁移到 Android Studio
- 将 HAXM 升级到 v1.5
- 升级了我的 SDK 工具 (24.4.1) 和我的平台 (23.0.1)
问题依旧,但log不一样了,更清晰了。有一个ClassNotFoundException
我无法解释:
10-28 20:26:05.102 2168-2168/com.example.myapp W/System: ClassLoader referenced unknown path: /data/app/com.example.myapp-1/lib/x86
10-28 20:26:08.583 2168-2168/com.example.myapp E/DataReductionProxySettingListener: No DRP key due to exception:java.lang.ClassNotFoundException: com.android.webview.chromium.Drp
10-28 20:26:09.393 2168-2213/com.example.myapp W/chromium: [WARNING:data_reduction_proxy_config.cc(423)] SPDY proxy OFF at startup
10-28 20:26:12.521 2168-2286/com.example.myapp A/chromium: [FATAL:gl_surface_android.cc(58)] Check failed: kGLImplementationNone != GetGLImplementation() (0 vs. 0)
10-28 20:26:12.521 2168-2286/com.example.myapp A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 2286 (GpuThread)
有什么想法吗? (我正在进一步调查,所以我会更新这个 post 如果我发现任何相关的东西)
此行为不是由 AVD 的任何错误设置或缺少任何先决条件(硬件等...)引起的。
作为cryptojuice mentioned in comments this was caused by an OpenGL ES prerequisite issue on emulator side:
#8 ...@chromium.org
Unfortunately OpenGL ES 2.0 support has been mandatory for devices
since at least Android 4.0, so we haven't ever explicitly supported
GLES 1.x at all and it was only working before by accident :/
It seems a bit problematic that the emulator (without host GPU
emulation) doesn't meet the minimum requirements for Android devices.
We might be able to work around this for the emulator at a significant
performance cost; we're talking to the emulator team about what the
best thing to do here is.
现在已修复(SDK 工具 25.1 RC1/平台 23 修订版 3),即使它没有出现在上面链接的票证上。
我刚刚在我的机器上创建了一个 API 23 模拟器:
- HAXM:v1.4,分配 1GB RAM
- AVD 基础:Nexus 4
- RAM:768MB,第二次尝试 896MB
- 堆:64 MB
- GPU 加速:无
我用我自己的几个应用程序尝试成功。但是每次我尝试将 WebView
用作 UI 的应用程序时,应用程序都会以这种方式崩溃:
此 logcat 的前三行仅与我的应用程序相关(以蓝色突出显示)。所有其他行都没有在 LogCat 的 'Application' 列中提及我的应用程序包的名称,但在消息中间有一行(用蓝色圈出)。
我可以将 HTML 代码加载到 WebView
中。崩溃发生在 setContentView(theWebView)
时间:
public class MyActivity extends Activity {
private WebView mWebview = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mWebview = new WebView(this);
mWebview.loadDataWithBaseURL("file:///android_asset/", HTML_CODE, "text/html", "UTF-8", null);
setContentView(mWebview); // THIS IS WHERE THE CRASH OCCURS
}
[...]
使用或不使用 runOnUiThread()
到 运行 mWebview.loadDataWithBaseURL()
产生完全相同的结果,这是预期的,因为 onCreate()
实际上是在 UI 线程上.
我使用的 html 代码没有任何改变。在上面的例子中,HTML_CODE
变量包含这个:
<html>
<head></head>
<body>
<h1>Hello</h1>
<p>Hello world!</p>
</body>
</html>
应用程序 运行 非常完美,即使在所有 API 我尝试了 17 和 19 种设备和模拟器。这就是我不解的地方。不过,我没有机会尝试使用实际的 Android 6.0 (API 23) 设备。
编辑
我刚刚:
- 从 Eclipse 迁移到 Android Studio
- 将 HAXM 升级到 v1.5
- 升级了我的 SDK 工具 (24.4.1) 和我的平台 (23.0.1)
问题依旧,但log不一样了,更清晰了。有一个ClassNotFoundException
我无法解释:
10-28 20:26:05.102 2168-2168/com.example.myapp W/System: ClassLoader referenced unknown path: /data/app/com.example.myapp-1/lib/x86
10-28 20:26:08.583 2168-2168/com.example.myapp E/DataReductionProxySettingListener: No DRP key due to exception:java.lang.ClassNotFoundException: com.android.webview.chromium.Drp
10-28 20:26:09.393 2168-2213/com.example.myapp W/chromium: [WARNING:data_reduction_proxy_config.cc(423)] SPDY proxy OFF at startup
10-28 20:26:12.521 2168-2286/com.example.myapp A/chromium: [FATAL:gl_surface_android.cc(58)] Check failed: kGLImplementationNone != GetGLImplementation() (0 vs. 0)
10-28 20:26:12.521 2168-2286/com.example.myapp A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 2286 (GpuThread)
有什么想法吗? (我正在进一步调查,所以我会更新这个 post 如果我发现任何相关的东西)
此行为不是由 AVD 的任何错误设置或缺少任何先决条件(硬件等...)引起的。
作为cryptojuice mentioned in comments this was caused by an OpenGL ES prerequisite issue on emulator side:
#8 ...@chromium.org
Unfortunately OpenGL ES 2.0 support has been mandatory for devices since at least Android 4.0, so we haven't ever explicitly supported GLES 1.x at all and it was only working before by accident :/
It seems a bit problematic that the emulator (without host GPU emulation) doesn't meet the minimum requirements for Android devices.
We might be able to work around this for the emulator at a significant performance cost; we're talking to the emulator team about what the best thing to do here is.
现在已修复(SDK 工具 25.1 RC1/平台 23 修订版 3),即使它没有出现在上面链接的票证上。