I'm sure there are many ways, but I used https://sabre.io/baikal/ to get a CalDAV and CardDAV server on cheap (shared, bog standard) web hosting, and then pointed Thunderbird to it. Apart from automatic syncing of contacts between devices, I can now edit my phone contacts on the desktop, which is so awesome.
It uses CalDav and CardDav to sync calendars and contacts with the android system, not with these apps.
If you build android from source it doesn't come with the GApps suite and you can use any other calendar and contacts apps which then use the calendars and contacts provided by the system.