Cross-project defect prediction enables a target software project with limited defect data to build a defect prediction model by leveraging abundant data in the source project. However, existing methods of cross-project defect prediction ignore the relative importance of global and local distributions in learning project-invariant feature spaces. This paper proposes a novel approach for cross-project defect prediction called Adan (autoencoder with dynamic adversarial adaptation) to dynamically adjust a project-invariant feature space by aligning global and local distributions simultaneously with adversarial learning. Specifically, the au-encoder was adopted to produce a latent space used as a project-invariant feature space for source and target artifacts. Global and local discriminators were used to adjust the latent space to ensure that representations of source and target artifacts in the project-invariant feature space have approximate global distribution and local distribution, respectively. The prediction model for the target artifacts was then trained using representations of the source artifacts in the project-invariant feature space. Experiments on four open-source projects with 12 pairs of tasks on cross-project defect prediction demonstrated that the proposed Adan approach outperformed state-of-the-art techniques, with an average improvement of 8.42% in terms of AUC.