We report on solar-blind metal-semiconductor-metal (MSM) detectors fabricated on stacks of (AI,Ga)N layers with different Al mole fraction. These structures were grown by molecular beam epitaxy on sapphire substrates to allow backside illumination and a low-temperature GaN buffer layer. They consist of a 0.3-0.4-mum active layer grown on a thick (AI,Ga)N window layer (approximate to 1 mum) that is transparent at the wavelength of interest. Different Al contents were used in the window layer. We observed that, in general, samples with a high Al content were cracked, which is explained in terms of mechanical strain. MSM photodetectors fabricated on these samples showed large leakage currents that ere correlated with the crack density. In order to reduce the strain and eliminate the cracks, we inserted an AIN layer between the buffer and window layer. A crack-free sample was obtained and the solar-blind photodetector fabricated on this structure showed record performance.