  We study 4D F-theory compactifications on singular Calabi-Yau fourfolds with
fluxes. The resulting N=1 effective theories can admit non-Abelian and U(1)
gauge groups as well as charged chiral matter. In these setups we analyze
anomaly cancellation and the generalized Green-Schwarz mechanism. This requires
the study of 3D N=2 theories obtained by a circle compactification and their
M-theory duals. Reducing M-theory on resolved Calabi-Yau fourfolds corresponds
to considering the effective theory on the 3D Coulomb branch in which certain
massive states are integrated out. Both 4D gaugings and 3D one-loop corrections
of these massive states induce Chern-Simons terms. All 4D anomalies are
captured by the one-loop terms. The ones corresponding to the mixed
gauge-gravitational anomalies depend on the Kaluza-Klein vector and are induced
by integrating out Kaluza-Klein modes of the U(1) charged matter. In M-theory
all Chern-Simons terms classically arise from G_4-flux. We find that F-theory
fluxes implement automatically the 4D Green-Schwarz mechanism if non-trivial
geometric relations for the resolved Calabi-Yau fourfold are satisfied. We
confirm these relations in various explicit examples and elucidate the general
construction of U(1) symmetries in F-theory. We also compare anomaly
cancellation in F-theory with its analog in Type IIB orientifold setups.
