In this paper, by combining modular forms and characteristic forms, we obtain general anomaly cancellation formulas of any dimension. For 4 k+ 2 dimensional manifolds, our results include the gravitational anomaly cancellation formulas of Alvarez-Gaum and Witten in dimensions 2, 6 and 10 (\cite {AW}) as special cases. In dimension 4 k+ 2, we derive anomaly cancellation formulas for index gerbes. In dimension 4 k+ 2, we obtain certain results about eta invariants, which are interesting in spectral geometry.