SQLiteException: no such column: metadata_dirty …

android.database.sqlite.SQLiteException: no such column: metadata_dirty (code 1): , while compiling: SELECT […]
FROM view_raw_contacts_restricted AS view_raw_contacts WHERE ((1=2)) AND ((dirty!=0))
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:179)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:421)
at android.content.ContentProviderClient.query(ContentProviderClient.java:145)

 

If you get an error message like this when DAVdroid is synchronizing contacts, it means that Android's contacts provider couldn't process DAVdroid's request because should be a field called metadata_dirty in your local contacts database, but it's not there. (See How does DAVdroid integrate with Android? to learn about the interaction between DAVdroid and the contacts provider.)

Why does this happen?

Android's contact database has changed in recent versions and new fields were introduced and used internally.

However, on some devices, the upgrade routine to Android 7 which should add this field is not executed correctly for some reason. This is an Android/firmware problem and does not only affect DAVdroid.

Solution

The error comes from the Android Contacts Provider, which resides in a system app called Contact storage (com.android.providers.contacts). To solve the problem, it's necessary to restore database integrity by deleting the local database:

  1. Save all your contacts (for example on the server). Make sure you have a reliable backup!
  2. On your Android device: Settings / Apps / System apps / Contact storage (com.android.providers.contacts¹) / Storage / Delete data
  3. Force synchronization in DAVdroid

This procedure deletes the local contact database including all local contacts. Android automatically creates the database again as soon as it used. DAVdroid will download all contacts again.

¹ may have a branded name on some devices, e.g. com.motorola.blur.providers.contacts

Last updated: 23 Apr 2018