If humanity ever encountered a hostile extraterrestrial species, a fully vegan human species would be too pacifist to fight. We wouldn't have developed as much technology and weaponry and would lose. Since we can't practice killing people because that would harm humanity too much, we need to kill animals by default as a sort of "target practice" to keep us sharp.
Whoever wins in a war against an alien species similar to ourselves is going to be determined by who is higher on the Kardashev scale. Animal agriculture is a huge drain on this energy gathering. Thinking of calories in terms of joules of energy (where 1 cal = 4.184 Joules exactly), the energy conversion of animal products is around 10%. That's a massive load on the system at every meal for self-indulgence's sake. So by eating meat, you're holding humanity back. We could be powering the next generation of technology with biofuels, but instead, we're dumping that wattage into livestock.
Shuttling defenseless animals into a slaughterhouse isn't somehow helping us develop defense technology against an intergalactic species that can obviously fight back. You don't practice self-defense on the comatose. This isn't helping us fight extraterrestrials.
The probability of an imminent alien attack is essentially zero; all of our listening to the night sky shows no signals of an impending threat. By contrast, >97% of climate scientists agree that climate change is an imminent threat. In addition, eating meat is also a probable threat to kick-start yet another global pandemic. So if you want to parry existential threats to humanity, it should probably start with not eating meat.
100% of worldwide starvation is caused by meat eating. So "not harming humanity" by killing animals instead... is harming humanity.