Nokia had a chance, but their developer experience was terrible. They should have invested in it. And also open source. They could have open sourced their platform and compete with Android.
What did they do instead? They made an extremely stupid bet on Microsoft, which by that time was even further behind in mobile world than Nokia itself.