问题描述
我使用的是 Android Studio 4.2.2.我创建了一个新项目,但没有在启动代码中添加任何内容,每当我单击 build 或 run 时,都会收到此错误:
I'm on Android Studio 4.2.2. I created a new project and haven't added anything to the starter code and whenever I click build or run, I get this error:
安装的构建工具版本 31.0.0 已损坏.使用 SDK 管理器删除并重新安装.
我查看了其他帖子的建议,但这些解决方案都没有奏效.这是我尝试过的:
I've looked at other posts' suggestions, but neither of those solutions worked. Here's what I've tried:
- SDK Manager → SDK Tools → 勾选Show package details",取消勾选 31.0.0,点击Apply";→ 卸载 31.0.0 → 检查 31.0.0 并重新安装
- 在 SDK 管理器中,取消选择 31.0.0 并尝试安装旧版本(例如,我尝试过 30.0.3)并更新buildToolsVersion".在 build.gradle 到安装的版本
- 前往Project Structure → Properties 并确认为Build Tools Version"选择了 31.0.0.和编译的 SDK 版本"
- 手动删除 build-tools 文件夹中的东西;即,
rm -rf/path/to/android/sdk/build-tools/31.0.0
(它不像其他一些帖子所描述的那样以-rc"结尾) - 重启 Android Studio
- 重新安装 Android Studio
- SDK Manager → SDK Tools → check "Show package details", uncheck 31.0.0, and click "Apply" → Uninstall 31.0.0 → check 31.0.0 and reinstall it
- In SDK Manager, deselect 31.0.0 and try installing an older version (e.g., I've tried 30.0.3) and update "buildToolsVersion" in build.gradle to the installed version
- Went to Project Structure → Properties and verified that 31.0.0 is selected for "Build Tools Version" and "Compiled SDK Version"
- Manually remove the stuff in the build-tools folder; i.e.,
rm -rf /path/to/android/sdk/build-tools/31.0.0
(it doesn't end in "-rc" like some other posts have described) - Restart Android Studio
- Reinstall Android Studio
我是一个 Android 菜鸟,只是想建立一个 hello world 项目,真的不应该这么难.
I'm an Android noob just trying to set up a hello world project, and it really shouldn't be this hard.
推荐答案
首先,我在Android Studio 4.2.2中遇到过这个问题,你不需要将SDK构建工具从31降级到30或更改编译SDK版本.
First of all, I faced this issue in Android Studio 4.2.2 and you do not need to downgrade the SDK build tool from 31 to 30 or change compile SDK version.
主要问题是 SDK 构建工具 31 中缺少的两个文件是:
The main problem is the two files missing in SDK build tool 31 that are:
- dx.bat
- dx.jar
解决方案是这些文件在文件位置命名为 d8,因此将其名称更改为 dx 即可解决错误.
The solution is that these files are named d8 in the file location so changing their name to dx will solve the error.
步骤如下.
前往该地点
go to the location
"C:UsersuserAppDataLocalAndroidSdkuild-tools31.0.0"
找到一个名为 d8.bat 的文件.这是一个 Windows 批处理文件.
find a file named d8.bat. This is a Windows batch file.
将 d8.bat 重命名为 dx.bat.
rename d8.bat to dx.bat.
在文件夹 lib(C:UsersuserAppDataLocalAndroidSdkuild-tools31.0.0lib")中
in the folder lib ("C:UsersuserAppDataLocalAndroidSdkuild-tools31.0.0lib")
将 d8.jar 重命名为 dx.jar
rename d8.jar to dx.jar
记住 AppData 是一个隐藏文件夹.打开隐藏项以查看 AppData 文件夹.
Remember AppData is a hidden folder. Turn on hidden items to see the AppData folder.
# change below to your Android SDK path
cd ~/Library/Android/sdk/build-tools/31.0.0
&& mv d8 dx
&& cd lib
&& mv d8.jar dx.jar
现在运行您的项目.
这篇关于Android Studio 错误“安装的构建工具修订版 31.0.0 已损坏"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!