Molecular oxygen has been the subject of many observational searches as chemical models predicted it to be a reservoir of oxygen. Although it has been detected in two regions of the interstellar medium, its rarity is a challenge for astrochemical models. In this paper, we have combined the physical conditions computed with smoothed particle hydrodynamics (SPH) simulations with our full gas-grain chemical model Nautilus, to study the predicted O2 abundance in interstellar material forming cold cores. We thus follow the chemical evolution of gas and ices in parcels of material from the diffuse interstellar conditions to the cold dense cores. Most of our predicted O2 abundances are below 1e-8 (with respect to the total proton density) and the predicted column densities in simulated cold cores is at maximum a few 1e14 cm-2, in agreement with the non detection limits. This low O2 abundance can be explained by the fact that, in a large fraction of the interstellar material, the atomic oxygen is depleted onto the grain surface (and hydrogenated to form H2O) before O2 can be formed in the gas-phase and protected from UV photo-dissociations. We could achieve this result only because we took into account the full history of the evolution of the physical conditions from the diffuse medium to the cold cores.