High harmonic generation (HHG) from solids offers a convenient means of producing coherent extreme ultraviolet (EUV) radiation. However, the achievable harmonic yield is greatly affected by propagation effects that the driving laser pulse experiences with spatiotemporal distortion when passing through solids. Here, we intend to optimize EUV harmonics generated from crystals by pre-shaping the driving laser pulse via spectral phase modulation through a genetic algorithm. Our experimental results obtained from MgO, sapphire and quartz crystals demonstrate EUV yield improvements, without increasing the incident laser fluence, up to an order of magnitude along with cut-off extension and selective harmonic enhancement. As a practical tool of compensating laser propagation effects, our method is expected to facilitate solid-based HHG applications such as high-energy photon spectroscopy and multi-petahertz signal processing.