Sync your Android contacts and calendars with your own server

It’s 2012, and there are still people who don’t put all their information onto Google/Facebook/… servers. Call them paranoid control freaks, if you want. 😉

Some of them even run their own e-mail server. Those people would probably prefer to have their address book(s) and calendar(s) stored on their own server as well, which Android cannot do out of the box.

This blog post aims to give a brief overview over my current solution to this problem. It’s not 100% perfect yet, but I am quite satisfied with it already. I have been using this setup for a couple of months now, and did not encounter any problems of relevance. (*)

Software components involved

On the server:

  • DAViCal – a free (GPL licensed) CalDAV/CardDAV server written in PHP; needs PostgreSQL as database server
  • Roundcube Webmail with the CardDAV plugin – to manage your contacts from within any web browser (Roundcube is of course also a decent mail client)

On the desktop / laptop computer:

  • Mozilla Thunderbird with
    • Lightning extension – to manage your calendar(s) from your Linux/Windows/Mac computer
    • SOGo connector extension (this link brings you to a file listing where you can download a nightly snapshot, there is no officially released version for current Thunderbird versions on the SOGo download page, yet) – to manage / lookup your contacts from your Linux/Windows/Mac computer

      A few words on how to get the SOGo connector working (it’s not really straight-forward, in my opinion): After installing the extension by dragging the downloaded .xpi file onto Thunderbird, open the Address book and choose Menu File / New / Remote Address Book. Enter the URL of your DAViCal CardDAV collection, i.e. https://your.server/davical/caldav.php/YOUR_USER/YOUR_COLLECTION. Then right-click on the new address book and choose Synchronize.

On the Android device:

  • CalDAV-Sync app from Market or AndroidPIT for a bit more than 2€

    (Since CalDAV-Sync is just a backend app that facilitates syncing, this is a screenshot of the Android calendar, with the event that can be seen in the Thunderbird-Lightning screenshot above)
  • CardDAV-Sync app from Market or AndroidPIT for a bit less than 1.50€ or free

    (Since CardDAV-Sync is just a backend app that facilitates syncing, this is a screenshot of the Android contact viewer, with the contact that can be seen in the Roundcube CardDAV screenshot above)
  • Contact Editor or Contact Editor Pro app from Market or AndroidPIT (Pro costs a bit more than 2€, the free version lacks a few features)

A few notes regarding the components:

  • Contact Editor is necessary because the default Android contact editor somehow does not work with custom contact sources. It integrates seamlessly once you have set it as default action upon adding/editing a contact for the first time after installation.
  • The SOGo connector extension for Thunderbird is a good start, but in the long run I really hope Thunderbird’s contact handling can be brought to a level that matches the rest of the application. There is hope.
  • There seems to be a calendar plugin for Roundcube as well (as part of the MyRoundcube plugin collection), and it seems to support CalDAV, but I couldn’t get it to work so far (and did not try hard, since I always have a Thunderbird with Lightning around, which is great for calendaring).

I’m planning to write more on how to get everything set up, but I currently don’t have time for that. The hardest part is getting DAViCal and PostgreSQL to work, in my opinion, all the other components basically just need a URL (to the previously set up DAViCal collection – e.g. https://your.server/davical/caldav.php/YOUR_USER/YOUR_COLLECTION), username and password to work.

Update (2012-01-28): Added some screenshots.
By the way, what must be a very recent change in Gentoo’s packaging of PHP causes CalDAV-Sync to fail syncing, and the apache error log contains “[Sat Jan 28 08:30:48 2012] [error] [client x.x.x.x] PHP Fatal error: Call to undefined function cal_days_in_month() in /…/davical/inc/RRule-v2.php on line 906” if you do not enable the ‘calendar’ USE flag for dev-lang/php (which is disabled by default).
Update (2012-01-29): (*) Typical, I write about something, and then it breaks. It seems there is an incompatibility between the newly released DAViCal 1.0.2 and CalDAV-Sync. The CalDAV-Sync developer has confirmed the issue and is working on it.
Update (2012-01-30): The incompatibility – resulting in logged error messages – does not affect functionality (it was just me having set the account to “One-Way-Sync”)
Update (2012-02-09): Great news: There are nightly builds of the SOGo connector Thunderbird extension that provides CardDAV integration for Thunderbird 10 now – I knew that extension before, but development seemed to have stopped at Thunderbird 3.5 or so. I added links and a bit of info above.
Update (2012-02-09/2): I found the first bug with SOGo connector – when saving a contact that has an image, the image gets lost. This doesn’t really matter to me, because I don’t use images in contacts usually, but for people who use images, this could be annoying. Hope they fix it.

29 thoughts on “Sync your Android contacts and calendars with your own server”

  1. The new editor in ICS checks the sync-adapter (CardDAV-Sync) for a certain attribute and enables editing capabilities if it finds it. So Contact Editor is not needed anymore with Android 4!
    Please note that you can’t actually edit all fields, also in 4.0.3 creating contacts is broken: http://code.google.com/p/android/issues/detail?id=24413

    NOTE: I quote the author “Releasing CalDAV-Sync and CardDAV-Sync open source is part of my plan.” 2€ are really well worth.

  2. owncloud is another option. it has less dependencies than davical and i found it pretty easy to set up.

    it integrates sabredav but well enough that you didn’t need to know that.

    worst part was figuring out what the right URL was.t

    1. Great info. Directly after I published this article I heard of owncloud for the first time, and I’ll be sure to try it out at the next opportunity (i.e. when a friend of mine wants to migrate his data away from Google’s servers, what he is about to do when he gets a new Android phone, which should be soon-ish).

    2. I agree – own cliff is pretty good. I have round cube running in owncloud with a card Dav plugin (from Graviox – i don’t recommend the my roundcube bundle) to share contacts.

      All I need now is tho get my android device to us it …

  3. What was the secret to getting DAVICal and PostgreSQL to work? I’m just starting on the config & any help is appreciated.

    1. Hi Ed,

      there isn’t really a “secret”, it was mostly me not being used to the PostgreSQL world, since I did everything with MySQL so far, and the web-interface of DAViCal also needs a little bit of getting used to.

      But why don’t you just try out SabreDAV? I didn’t know about it earlier, but it seems to provide the same functionality as DAViCal, and it can use a MySQL (or Sqlite) backend.

  4. Like your blog! Exactly what I was looking for, as someone who was running roundcube witch a postfix server. And would like to sync contacts and calendar with my android.
    Set up owncloud. Contacts syncing works perfectly!

    My question/remark is about the calendar. Isn’t it kind of double to have to installe both Owncloud AND Davical. It seems that Owncloud has calendaring as well.
    So if I could connect the Roundcube calendar to Owncloud with caldav. There would no need to install Davical at all. Saving me trouble of installing PostgreSQL as well, as everything is running on MySQL.

    Or am I missing somehting completely obvious?

    Having said that. Same as you, I’ve been unsuccesfull in syncing owncloud-roundcube calendars.
    Not sure wether this is because I’m doing something wrong, or that it is just not possible.

    Any thoughts on this?

  5. i want to synchroinize mysqlite database of my android phone with cloud server..does anybody know how to do it?
    can you please give me some sample codes or tutorial for this

  6. Thanks for writing up all this up Patrick. I’ve been somewhat frustrated about how hard it is to synchronize an android phone without using anyone else’s server. Between my desktop and my laptop I simply unison ical files back and forth and have lightning use them as a backend — works flawlessly (lightning write straight to the file so changes are atomic). No idea if something similar might work in android?

    I managed to get contact synchronization to work now using carddav and could probably also do calendaring though I’m not crazying about buying a not-yet-open-sourced app (or handing over my CC to google) but I’ve noticed a problem on the desktop side of things. While I can link a caldav calendar to Lightning and add events while the server is online I am not able to add events when the server is inaccessible. So Lightning is not really syncing with the server so much as using it as a backend. Do you know if there’s any way to have Lightning only sync with the server when I want it to but to also allow me to add events offline?

    thanks

  7. In case it hasn’t been mentioned yet:
    owncloud

    Might be a solution for many people who would like to use cloud funcionality but don’t want to have their data stored (and perhaps looked over) by some company.

  8. I like the concept of syncing my calendars without using cloud services such as Google. For quite a while, I have been USB syncing with my Android phone using Birdiesync. It works quite well. I only sync my calendar. It works with Thunderbird Lightning, and with both Windows and Android phones.

    I would like to get it also syncing with my company server so my calendar is available to others at my company, so I will be looking into the suggestions in this blog.

    Thanks,
    Charlie Morrison

  9. I have the same setup as yours. However, all Chinese characters can not be shown properly under the roundcube carddav plugin. It is ok with the iOS, Mac and Thunderbird.

    I wonder any thing need to be amended inside the carddav plugin.

    Thanks,
    Gene Leung

  10. Another way to achieve this is to use Horde and to set up active sync; then set up an “enterprise” account on the device. On the desktop side, Lightning would work with caldav.

    I suppose other groupware solutions can work, too.

  11. I’d be interested to know if/what you do for tasks.

    I tried caldav sync before but I don’t think it supports tasks.

    I use funambol…some of the builds support tasks and it works ok, but full caldav with tasks would be nicer.

  12. Very interesting article, I will definitively try something like this when I have some time.
    I had a quick look at Funambol but it doesn’t work out of the box.

    I’m still not sure about a certain use case:
    I have a gmail account configured on my phone, if I use your solution and create calendar entries, will they be on Google Calendar anyway or not?

    Thanks

  13. OK, this looks great, just what I need. Please read this for background. http://www.facebook.com/notes/carolus-bergh/cloud-computing-and-the-third-world/110663772463153

    We don’t have cloud cover in the worlds outside the USA and Europe. South Korea is well equipped but Australia, Africa and South America lags far behind, especially outside of the cities.

    Our problem is that mobile phones, tablets and computers now get equipped for cloud computing while our infrastructure globally will require 5 – 15 years to get up to speed. It simply is absent in most places.

    Therefore, we need to be able to sync essential data such as contacts, calendar, tasks, notes/memo’s and business-related user data directly between devices.

    I am a noob with only a few short years of Linux user experience and no training.

    Does this solution mean that I can set up a Funambol server on my laptop and sync directly with my smartphone, over Bluetooth or USB?

    How do I install Funambol software on Ubuntu or Mint?

    Please help! reneg8or [at] geemail dot com (gee – G)

    1. Hello Carolus, thanks for your comment. The link goes to a facebook page which is only accessible for facebook users – so I can’t read it. But I see your point, syncing contacts / calendar etc. via the Internet only works when you have an affordable and good enough Internet connection.

      Anyway, I think it’s too off-topic for this blog post, and also I don’t know the answers to your questions.

  14. Anyone managed to sync Android 4.2.2 contacts with Owncloud contacts using webdav, or whatever…? Seems like some succeded, but I really can’t se how.

  15. hi, This is exactly what I would like to do. however it’s paramount for me to be able to use a nosql db server and oauth2. does anyone know how to go about it ?
    many thanks

    Luca

  16. Thanks for every other informative site. Where else could I am getting
    that type of info written in such an ideal approach?
    I’ve a venture that I’m simply now operating on, and I have been at the glance out for such info.

Leave a Reply

Your email address will not be published. Required fields are marked *