我用的是Android Studio 4.2.2。我创建了一个新项目,还没有添加任何东西到启动器代码,每当我点击构建或运行,我得到这个错误:

已安装的构建工具版本31.0.0已损坏。使用SDK管理器删除并重新安装。

我看了其他帖子的建议,但这些解决方案都不起作用。以下是我的尝试:

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!项目,真的不应该这么难。


当前回答

如果你仔细看日志,你会发现:

Build-tool 31.0.0在path-to-sdk\build-tools\31.0.0\ DX .bat中丢失DX

您可以尝试从以前的版本中复制它,但如果您必须告诉整个团队做同样的事情,并且在服务器管道上仍然失败,那么这就不太合适了。我在31.0.0-rc5发布时也遇到了这种情况。

其他回答

我在SDK管理器下选中31,单击Android 11.0(R)恢复到30,并更新Build Gradle(项目)将compileSdkVersion和targetSdkVersion从31更改为30。

我还必须将buildToolsVersion更新为“30.0.2”而不是30。现在它起作用了。

我从https://android.googlesource.com/platform/dalvik/+/master/dx/etc/dx.bat下载了dx.bat文件。

我把它放在\build-tools\31.0.0中,然后下载了dx.jar文件(根据我得到的错误消息,该文件也丢失了) 从http://www.java2s.com/Code/Jar/d/Downloaddxjar.htm。

我把它放在目录\build-tools\31.0.0\lib。

然后就成功了。

更改您的Gradle构建从:

android {
    compileSdkVersion 31
    buildToolsVersion '31.0.0'

    defaultConfig {
        applicationId "com.example.eg"
        minSdkVersion 23
        targetSdkVersion 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

to:

android {
    compileSdk 31

    defaultConfig {
        applicationId "com.example.eg"
        minSdk 23
        targetSdk 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

这是可行的。

为了解决这个问题,首先去以下位置:

C:\Users\User\AppData\Local\Android\Sdk\构建工具\ 31.0.0

然后找到文件d8 (Windows批处理文件)并将其重命名为dx。

然后转到:

C:\Users\User\AppData\Local\Android\Sdk\构建工具\ 31.0.0 \ lib

然后找到文件d8(可执行Jar文件)并重命名为dx。

你的问题现在可以解决了。

31.0.0版本本身已经损坏,我们需要降级到30。

我遵循同样的步骤:

打开项目结构→按Ctrl + Alt + Shift + S 进入模块→属性→*编译SDK版本:30构建工具版本:30.0.2 进入默认配置→目标SDK版本:30 应用并关闭。 菜单工具→SDK管理器 在我的情况下,取消选中API 31以卸载,并选中Android 11.0(R)以安装(30.0.3)。 适用。