How did a plant evolve to know there were animals alive that would eat it's fruit when it decided to produce this fruit?
The plant does not "know" there are animals. It is just that plants, that accidentally evolved (due to mutations) a fruit that attracts animals (which can spread its seeds etc.) had an advantage over plants that did not have them. The disadvantaged plants just became extinct after a while. And you must be aware that the first fruits were rather "pre-fruits", but already a selective advantage to their bearers.