9

I've been getting reports of SQLiteDiskIOExceptions for some time now (via Flurry/acra). I haven't been able to reproduce the issue locally, but it's my most frequent crash, occurring up to once in fifty sessions on a bad day. They seem to be particularly frequent under Android 2.3.x.

I make absolutely no use of SQL in my own code, but I have more than one WebView running simultaneously (two, plus an ads SDK). The errors all appear to be caused by a WebView, via one of any of the following methods:

  • android.webkit.WebViewDatabase.clearCache
  • android.webkit.WebViewDatabase.flushCacheStat
  • android.webkit.WebViewDatabase.deleteCookies
  • android.webkit.WebViewDatabase.removeCache

(Also received a couple of reports of an android.database.sqlite.SQLiteDatabaseCorruptException , but these are extremely rare). I commented out anything relating to clearing the WebView cache in my own code, but that didn't help.

Full LogCat dumps here.

Does anyone know of any way I could prevent, catch, or more clearly isolate the cause of these exceptions? They're too frequent to just be caused by bad SD memory.

Thanks!

Edit: Source code by request:

  browser=(WebView)findViewById(R.id.webkit);
  browser.setWebViewClient( new CustomWebViewClient(this,browser) );
  WebSettings webSettings = browser.getSettings();
  webSettings.setJavaScriptEnabled(true);
  webSettings.setPluginsEnabled(true);
  browser.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);
  webSettings.setBuiltInZoomControls(true);

  browser.setWebChromeClient(new WebChromeClient() {
    public void onProgressChanged(WebView view, int progress) {
      progressbarhorizontal.setProgress(progress);
    }
  });

XML:

        <WebView android:id="@+id/webkit" android:layout_width="fill_parent" android:layout_height="fill_parent" android:focusable="true" android:nextFocusDown="@+id/bottomview"></WebView>
Sven Viking
  • 2,660
  • 21
  • 34
  • Please show how you are implementing webview. – Lalit Poptani Aug 28 '11 at 04:44
  • Edited the question to include code. I did see this: http://stackoverflow.com/questions/3130654/ recently, and for that reason am thinking about creating the WebView programmatically instead of using XML. – Sven Viking Aug 28 '11 at 15:57
  • @SvenViking Did any of the solutions below work for you? – tarkeshwar Dec 19 '11 at 07:34
  • tarkeshwar: Not entirely. I did find that a method of clearing the cache that I added to try to solve the problem was actually making it worse, though, so by reverting that I was able to reduce the frequency of the errors to vaguely tolerable levels. – Sven Viking Dec 22 '11 at 16:36

3 Answers3

5

You may be able to utilize setUncaughtExceptionHandler() in order to catch the exception and gracefully handle it.

NuSkooler
  • 5,391
  • 1
  • 34
  • 58
3

I too am struggling to find the exact source of these errors. I have found a thread on the Google Groups AdMob forum that suggests it might be related to the AdMod SDK. For me, these errors started showing up after I published my latest update, which among other changes included upgrading the AdMob SDK from v4.1.1 to v4.3.1. Are you using AdMob?

Seems that the AdMob SDK in some circumstances manipulates its WebViews off of the UI thread, which I guess could cause various problems, possibly i.e. concurrent SQLite access from different threads when managing the cache. Possibly related to SQLiteDiskIOException in Android. Might also be worthwhile checking that your own code does not manipulate WebViews off of the UI thread.

Community
  • 1
  • 1
Leif R.
  • 101
  • 3
  • Leif: I'm using AdMob and MobClix. I'd guess that several ad SDKs cause or aggravate this issue, and using more than one together multiplies the problem due to conflicts. Thanks, good point about ensuring WebView stuff is kept on the UI thread. – Sven Viking Jan 21 '12 at 07:00
2

There is an issue reported in code.google site.

EDIT : If you are ready to disable the cache, the exception's frequency might decrease a bit.

try
{
  Method m = CacheManager.class.getDeclaredMethod("setCacheDisabled", boolean.class);
  m.setAccessible(true);
  m.invoke(null, true);
}
catch (Throwable e)
{
  Log.i("myapp","Reflection failed", e);
}
Ron
  • 24,175
  • 8
  • 56
  • 97
  • Thanks. I had actually seen that before, but it doesn't really help me. The crash is being reported quite frequently, and knowing it'll probably be fixed in some future version of Android (which probably won't see widespread adoption for a number of years) is a small comfort :/. What I'd like to know is whether there's any way to work around the problem as is, like extending WebView and catching the SQL errors in a custom class or something. (Guessing that could be tricky due to all the different WebView revisions in different Android releases)... – Sven Viking Aug 27 '11 at 21:53
  • Thanks, I may consider that if no better solution can be found. The cache is pretty useful for my app, though :(. – Sven Viking Aug 28 '11 at 15:47