Announcing it gives the military a chance to control the narrative. If a photographer snaps a test flight and it appears on Gizmodo with the headline "Military testing secret drone swarms to kill us all", there'll be a massive public outcry, a huge negative PR cycle, possible a Congressional inquiry, and in the course of doing damage control the military will have to reveal more secrets than if they just announced the project in the first place.
Americans are not shy about inventing details when they have none, and also have a tendency not to trust either their government or the press.
When you can advertise that you're cutting edge, it helps attract the best minds. That's dramatically more valuable than worrying about eg China or Russia stealing the idea to Gremlins. Those ideas and technologies get out regardless, you can't protect them very long. Competitors and adversaries are going to catch up with a given piece of technology, even if they have to figure out how you did it the hard way. By recruiting the best minds to work on problems, you can ensure that you remain a lap ahead of the competitors that will steal or copy from you regardless. If something is very sensitive, then perhaps you can buy a bit more time by keeping it strictly secret, it's still going to get out. If your tech is good enough, powerful countries will do anything to get at it.
30 years after the Cold War when Russia opened their soviet archives, it turned out that they were never secret at all.