You let them be friends? Are ye daft!?
All kidding aside, letting the AI set up friendly relations is unwise in almost all circumstances. Whenever you have contacted AI, try to get them to war one another unless it is very inconvenient for YOU if they do. If they fight eachother, they will waste precious resources not fighting you and are also less likely to attack you, which gives you more time and space to dictate events. As Julius Ceasar said "Divide and Conquer".
Now, if that tactic has somehow failed, there are some strategic pointers: You do not need your fleet to be on all fronts at once. The most important insight is that galciv wars aren't won in space, but they're won on the ground. If your transports are fast enough and you can sneak a fleet in to kill the defenders around poorly defended planets, you can gain territory in spite of enemy fleet supremacy. The AI isn't very good at taking planets, so just pick off easy targets if your fleet is too weak to fight the enemy in space, keep transports standing by to immediatly reclaim lost planets and generally all will be well. Just remember, if you can't be stronger, you should be faster!