The answer lies in the theory of evolution. Like all the other organisms, the primary purpose of trees and plants, too, is reproduction so that their species continues to propagate itself. Since trees and plants can’t move around for reproduction, they have to depend on animals and birds. After an animal or bird eats the fruit along with the seeds within it, naturally the seeds travel in the stomach of the animal or bird who eat the fruit. This way the seeds travel far and wide and are released away from the place they originated at. This is how trees and plants reproduce.
During the process of digestion, however, the seeds have to endure acidic digestive juices. It is necessary for the seeds to have developed strong enough protective layer on the exterior so that they don’t get dissolved in the stomach’s acids. This protective layer is not formed overnight, but take days. In fact, that is the last stage of fruit’s growth. During this time the fruit should not be noticed by animals and birds. Hence, in order to camouflage with green leaves around them, fruits remain green in color. Their taste is also not enjoyable during this time. Only after the protective layer is formed around the seeds do fruits become colorful and attract animals and birds to eat them. They produce glucose and develop sweet taste as well as emit fragrance. All of this to attract animals and birds to eat them so that the now-ready seeds are dispersed.
You might also like: