android - 非常简单的 WebView 在 API 23 模拟器下崩溃

标签 android android-emulator android-webview android-6.0-marshmallow

我刚刚在我的机器上创建了一个 API 23 模拟器:

  • HAXM:v1.4,分配 1GB RAM
  • AVD 基础:Nexus 4
  • RAM:768MB,第二次尝试 896MB
  • 堆:64 MB
  • GPU 加速:无

我用我自己的几个应用程序成功地尝试了它。但是每次我尝试使用 WebView 作为 UI 的应用程序时,应用程序都会以这种方式崩溃:

enter image description here

此 logcat 的前三行仅与我的应用有关(以蓝色突出显示)。所有其他行都没有在 LogCat 的“应用程序”列中提及我的应用程序包的名称,但在消息中间有一行(用蓝色圈出)。

我可以将 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 设备和模拟器上使用更高级的 HTML+CSS+JS+JS<->Java 绑定(bind)代码也是如此。这就是我不解的地方。不过,我没有机会尝试使用实际的 Android 6.0 (API 23) 设备。

编辑

我刚刚:

  • 从 Eclipse 迁移到 Android Studio
  • 将 HAXM 升级到 v1.5
  • 升级了我的 SDK 工具 (24.4.1) 和我的平台 (23.0.1)

问题仍然存在,但日志有所不同,并且更加清晰。有一个 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)

有什么想法吗? (我正在进一步调查,所以如果我发现任何相关内容,我会更新这篇文章)

最佳答案

此行为不是由 AVD 的任何错误设置或任何缺少先决条件(硬件等...)引起的。

作为cryptojuice评论中提到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 rev 3),即使这没有出现在上面链接的票证上。

关于android - 非常简单的 WebView 在 API 23 模拟器下崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32788237/

相关文章:

android - 如何收听 webview url 单击和启用/禁用操作栏上的按钮

android - 覆盖Android中文本选择(在WebView中)的默认上下文操作栏

java - Android:媒体播放器流在几分钟后停止播放

android - 如何在更改 EditText 文本时更改 TextView 文本?

Android 模拟器的 GPS 位置给出了错误的时间

android - 启动监控失败,不运行程序。为什么?

android - 如何使用 Genymotion 在 PC 上启动 Android 应用程序?

安卓 : View Internal storage file in webview

java - NoClassDefFoundError : Failed resolution of: Lcom/parse/ui/R$layout; on pre-Lollipop

android - 在 Android 中使用 Html.fromHtml 将颜色设置为 TextView 不起作用