  In this work, we study cosmological solutions of the 8-dimensional Einstein
Yang-Mills theory coupled to a perfect-fluid matter. A Yang-Mills instanton of
extra dimensions causes a 4-dimensional expanding universe with dynamical
compactification of the extra dimensions. To construct physically reliable
situations, we impose the null energy condition on the matter. This energy
condition is affected by the extra dimensions. Then, we consider cosmological
constant to grasp the structure of the solution space. Even in this simple
case, we find several interesting solutions, such as bouncing universes and
oscillatory solutions, eventually arriving at a de Sitter universe with
stabilized compact dimensions. In addition, we consider a class of matters
whose energy density depends on the volume of the extra dimensions. This case
shows another set of bouncing universes. Also, a real scalar with potential is
taken into account. The scalar field model admits de Sitter solutions due to
the choice of potential, and we demonstrate how potentials can be constructed
using flow equations. {\color{black}Thus, what we discuss in this work is based
on the 8-dimensional Einstein frame, which corresponds to the 4-dimensional
Jordan frame by dimensional reduction. Consequently, the results are derived in
the 4-dimensional Jordan frame, not in the 4-dimensional Einstein frame.
