Spark Shell with Yarn - Error: Yarn application has already ended! It might have been killed or unable to launch application master

I've managed to solve the problem by using more or less the same method described by the answer by Liming Cen to this similar question.

The only difference was that I added to my HDFS all the JARs contained in $SPARK_HOME/libexec/jars, compressed in a zip file.

In $SPARK_HOME/libexec/conf/spark-defaults.conf I then added the following line:

spark.yarn.archive=hdfs:///user/MY_USERNAME/spark-archive.zip