  We analyze about 12 years of Fermi-LAT data in the direction of the Andromeda
galaxy (M31). We robustly characterize its spectral and morphological
properties against systematic uncertainties related to the modeling of the
Galactic diffuse emission. We perform this work by adapting and exploiting the
potential of the skyFACT adaptive template fitting algorithm. We reconstruct
the gamma-ray image of M31 in a template-independent way, and we show that flat
spatial models are preferred by data, indicating an extension of the
$\gamma$-ray emission of about 0.3-0.4 degree for the bulge of M31. This study
also suggests that a second component, extending to at least 1 degree,
contributes to the observed total emission. We quantify systematic
uncertainties related to mis-modeling of Galactic foreground emission at the
level of 2.9%.
