問題描述
我使用的是 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 管理器刪除并重新安裝.
Installed Build Tools revision 31.0.0 is corrupted. Remove and install again using the SDK Manager.
我查看了其他帖子的建議,但這些解決方案都沒有奏效.這是我嘗試過的:
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 已損壞"的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!