When we download other people's projects from github, we will re-download the Gradle files. In other words: We downloaded a new Android studio, and moving the original old project to the new Android studio will cause Gradle to be inconsistent with the current Gradle.
We know that there is no problem with the code, but the running environment is different.
First, create a new project and find out the version number and JDK
Create a new project and run it, you can find the version number of the project (under the Poject directory->build.gradle) and JDK
(check gradle in files->setting->Build, Execution, Deployment->Build Tools- >Gradle)
Attached are my version numbers (Figure 1):
JDK and Gradle (Figure 2)
The first step is to open the .gradle file in the root directory of the project that needs to be moved.
Find the file location of your original project, open the .gradle file, delete all the files inside, then copy the contents of your current .gralde file and paste it into your original project. This is the gralde of my original project.
Find the project you just ran normally, open the gradle file, copy all the files, and paste them into the new .gradle.
The second step is to open the build.gradle file (open with Notepad)
Change the version to the version in Figure 1. I have already changed it here.
The third step, open the gradle file, find and open the gradle-wrapper.properites file
Changing the path of distributionUrl to the gradle in Figure 1
may cause you to re-download gradle, pause it, then set the relative path of gradle, and change the path of Gradle JDK to the version in Figure 2. Please see my other blog: Every time you create a new project, gradle will be re-downloaded
After these three steps of modification are completed, the project can be opened and run normally.