Is it all right to use "in hopes of" to mean "with the aim of"?

I would agree with the with the aim of definition, but with the addition that it should have enough chance of failure to warrant a degree of hope.

"I went to the corner shop, with the aim of buying some milk" (or simply "to buy some milk") is a straight-forward plan and its execution. You'd expect me to soon have some milk.

"I went to the corner shop, in hopes of buying some milk" would imply that the shop often didn't have milk,* so it was in no way a given that I would succeed.

*Or that I was really absent minded, or didn't know where the shop is, or some other reason that could lead to the plan failing.