Oh, and at least for Swiss German: It is kinda a different language (but extremely related to the written German): It's not just an accent with some funny words, but has a slightly different grammar, too. Most glarious is the lack of most of the verb tenses in Swiss German. So pupils have to learn quite some stuff to be really fluent in written German.
And even just within Switzerland there are dialects I don't understand (as in no clue what they're talking about). People speaking these usually switch to a more conformistic pronounciation when talking to people from other areas and don't use some of the more obscure words.
And for the reasons this all exists (at least for Switzerland): It's cultivated and all kinda part of your local/national identity. Politicians who speak a "too good" written German are deemed suspicious, almost all of the local culture (theater, local movies, even most of the Swiss tv produciton ...) is in Swiss German.
[Native Swiss German speaker, here.]