Destroy Enemies and Then Build Temple

The Gemara in סנהדרין mentions that there are three Mitzvot that we are commanded to observe when we enter Eretz Yisrael.

We are to appoint a king, destroy the seed of Amalek, and build the Beit Hamikdash.

It is not clear whether we are to build the Temple first or destroy Amalek first. We have our answer from the order of the Parsha. It is first mentioned that we are to push aside our enemies and then build the Temple.

Rabbi Soloveitchik wrote that Amalek represented pure evil. There was nothing to gain by attacking the Jews in the desert. They did not have their own land at that time. The Rav said that anyone who wishes to destroy Israel, is Amalek.

It is understandable that our enemies and evil must be destroyed before the light of the Beit Hamikdash is kindled.

It is not clear if we are to first bui