Rav Hirsch explains this at length in Beraishis 4:3-6
3 Now it came to pass at the end of days, that Cain brought of the
fruit of the soil an offering to the Lord.
4 And Abel he too brought of the firstborn of his flocks and of their
fattest, and the Lord turned to Abel and to his offering.
5 But to Cain and to his offering He did not turn, and it annoyed Cain
exceedingly, and his countenance fell.
6 And the Lord said to Cain, "Why are you annoyed, and why has your
Rav Hirsch explains that it was the intent behind the sacrifices that made the difference and not the content of the sacrifices.
Two people can bring exactly identical offerings, pray exactly the
same prayers, and still present themselves to Hashem in infinite
dissimilarity. That is clear just here at the very first offering. It
does not say her: Hashem turned to Abel's offering and did not turn
to Cain's offering, but He turned to Abel and his offering but to
Cain and his offering He did not turn. The essential difference lay in the
person of the offerer not in the offering itself. Cain's
attitude was unpleasing and therefore his offering was unpleasing too.
Perhaps some nuances in what is told us reveal a difference in the
attitude of the two brothers. It was מקץ ימים, after some time had
passed, accordingly, after a time in which Cain's fields and Abel's
flocks had flourished under Hashem's blessing. So there was occasion
for an offering of acknowledgement.
Cain brings to Hashem ממפרי האדמה, some of theproduce of the earth,
any, withpout choice. After all, he must offer Hashem too,
"something". This shows that objectionable attitude which Malachi
later censures so severely. The attitude which looks on our
relationship to Hashem and the godly, "religion", as it is called, as
something which also belongs to our affairs, something which is not to
be entirely left out, and so we can devote just the "spare moments of
life" to it, and give "the lame and the sick, and whatever else is
useless" to it. וניבו נבזה אכלו is how Malachi describes it. "All that
the Altar gets is food which is otherwise despised. It is that
allegiance which is only brought by fear, which supports temple and
church in the same spirit as it builds hospitals and prisons.
But Abel took מבכורות צאנו ומחלביהן, took some of the firstlings of
his flock, and of those the very best. He who brings the first and the
best, places his relationship to Hashem and the godly in the
foreground, for him this relationship is the first and most important,
to which all the rest of his life is only accessory; more, offering
the "first" is always taken in the Torah as representative dedication
of all the rest.
Additionally, Rav Hirsch points out that Cain was, as the bchor (first born), the representative of the family and his sacrifice was supposed to represent the entire family. Thus Abel was not originally supposed to have to bring a sacrifice at all. It was only because Cain did not bring a proper sacrifice that Abel felt compelled to later bring his own.
So here too we should have expected that Abel would have been included
and represented in Cain's offering and that there would have been no
occasion for him to bring a separate one. But if in spite of that it
is stressed that Abel גם הוא, he also brought an offering, then either
Abel did not feel himself represented in Cain's offering, or Cain,
caught up in his egoism, did not want to include him also. From what
follows the first supposition seems more likely.