Where did the apple that Altair hides in the library come from?
Solution 1:
This whole answer is chock full of spoilers about the AC universe and story. Hopefully you already knew this from the huge spoiler tag in the question. :)
There are multiple Pieces of Eden in the Assassin's Creed universe. The Templars are searching for them in the first game, which is why they're curious about Desmond's memories of Altair - at the end of the first game he holds the Piece of Eden and it displays a globe with locations marked. These are the locations of other Pieces of Eden.
In some of the "secret" memories that you can use to unlock "The Truth" in the series, you're told that Pieces of Eden have influenced or allowed great leaders from history to rise to power. The Templars plan to use many Pieces of Eden, in concert with a vast amplification network, to extend their control over the entire world at once.
The Piece of Eden that Ezio locates in Assassin's Creed 2 is different from the one Altair had - this one the Templars have already recovered from wherever it had been previously hidden or kept. Ezio takes it from the Templars twice, and finally hides it for Desmond and the Assassin team to recover later in AC: Brotherhood. (This is the piece Desmond takes right before stabbing Lucy)
At the end of Revelations, Ezio recovers Altair's Piece of Eden, which Altair had possessed from the end of the events of the first game until his death. The memories that Ezio recovers from the library keys tell the story of how this device effected the assassin brotherhood in the years following the original game.