AS officially recommends using the latest version, but due to some reasons, it may not be the latest version. When I was setting up the environment today, the AS version I used was 4.1.1, and I reported the error in the title. The IDE prompted to uninstall and re-download and install. I did so, but the problem still exists. Since 34.0.0 doesn't work, can others work? I also downloaded other versions and found that 29.0.0 is ok.
So I went online to find the reason: I found this solution. Original blog:
According to the build error message "The 31.0.0 version of the build tool is missing the DX file" and the solution from StackOverflow, it is found that the 31.0.0 version of the build tool is missing the two files "dx" and "dx.jar". The correct way It is to copy the two files "d8" and "d8.jar" corresponding to the path to create copies, and rename them to "dx" and "dx.jar" respectively. The approximate path of the two files "d8" and "d8.jar" is :
C:\Users\user\AppData\Local\Android\Sdk\build-tools\31.0.0\d8
C:\Users\user\AppData\Local\Android\Sdk\build-tools\31.0.0\lib\d8.jar
Just change these two names.