shadow
shadow

Reputation: 124

Webview crash with simple HTML and throw JNI error

Hi,i try to load an webview and i dont know why some HTML make app crash with the logs above.i have to say that the html is really simple

<style type="text/css">
    body {
        font-size: 14;
        text-align: justify;
        max-width: 100%;
        word-break: break-all;
        word-break: break-word
    }
    
    img {
        display: inline;
        height: auto;
        max-width: 100%;
    }
    
    iframe {
        display: inline;
        height: auto;
        max-width: 100%;
    }
</style>
<html>

<body>
    <p align="justify" line-height="1.5">
        <p class="p1"><span class="s1" style="caret-color: rgb(0, 0, 0); -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: 100%; background-color: rgba(255, 255, 255, 0);"><font color="#000000" face="sans-serif" size="3">[ TxxxxY]&nbsp;</font></span></p>
        <p class="p1"><span class="s1" style="caret-color: rgb(0, 0, 0); -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: 100%; background-color: rgba(255, 255, 255, 0);"><font color="#000000" face="sans-serif" size="3">xxxx,&nbsp;</font></span></p>
        <p class="p1"><span class="s1" style="caret-color: rgb(0, 0, 0); -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: 100%; background-color: rgba(255, 255, 255, 0);"><font color="#000000" face="sans-serif" size="3">xxxxy.&nbsp;</font></span></p>
        <p class="p1"><span class="s1" style="caret-color: rgb(0, 0, 0); -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: 100%; background-color: rgba(255, 255, 255, 0);"><font color="#000000" face="sans-serif" size="3">* xxxxxx9.&nbsp;</font></span></p>
        <p class="p1"><span class="s1" style="caret-color: rgb(0, 0, 0); -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: 100%; background-color: rgba(255, 255, 255, 0);"><font color="#000000" face="sans-serif" size="3">*xxxxxxố 5&nbsp;</font></span></p>
        <p class="p1"><span class="s1" style="caret-color: rgb(0, 0, 0); -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: 100%; background-color: rgba(255, 255, 255, 0);"><font color="#000000" face="sans-serif" size="3">xxxxxxxxxxxxxxxxx!</font></span></p>
        <p class="p1"><span class="s1" style="caret-color: rgb(0, 0, 0); -webkit-tap-highlight-color: rgba(26, 26, 26, 0.301961); -webkit-text-size-adjust: 100%; background-color: rgba(255, 255, 255, 0);"><font color="#000000" face="sans-serif" size="3"><br></font></span></p>
    </p>
</body>

</html>

and the load weview method

   if (Build.VERSION.SDK_INT >= 19) {
            webView.setLayerType(webView.isHardwareAccelerated() ? View.LAYER_TYPE_HARDWARE : 
           View.LAYER_TYPE_NONE, null);
        } else {
            webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        }

webView.loadDataWithBaseURL("", html, "text/html; charset=utf-8", "utf-8", "");

I think it look like something about JNI.so please any suggest about this

Upvotes: 0

Views: 212

Answers (1)

kukroid
kukroid

Reputation: 420

Not sure of the JNI error, but I tried your html with this approach and it worked fine.

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_webview)
    web.settings.javaScriptEnabled = true
    web.loadUrl("file:///android_asset/myhtml.html");
}

May be try running in a different emulator or device. It might be emulator specific issue

Upvotes: 1

Related Questions