Robert Lewandowski has announced he will leave Barcelona at the end of the season when his contract expires.