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


当前回答

我还没有足够的声誉评论,但有一个解决方案与符号链接的Windows,我想补充说,它也适用于macOS。

这是Mac终端的命令:

ln %ANDROID_HOME%/sdk/build-tools/31.0.0/d8 %ANDROID_HOME%/sdk/build-tools/31.0.0/dx && ln %ANDROID_HOME%/sdk/build-tools/31.0.0/lib/d8.jar %ANDROID_HOME%/sdk/build-tools/31.0.0/lib/dx.jar

其他回答

更改您的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"
    }

这是可行的。

将gradle升级到7.0.2可能会有所帮助

这是一个与Android studio和SDK 31冲突的问题。

转换您的构建。Gradle文件是这样的:

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.example.app"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
}

针对android 12目标sdk API 31

compileSdkVersion 31
buildToolsVersion 31.1.0

Android gradle插件(AGP)应该有最低版本设置为

7.0.2 or above

Android gradle包装版本可以设置

gradle-7.2-bin.zip

通过上述配置,构建错误将得到解决,您无需将构建工具版本降级到30.0.2

此外,如果你面临和intellij注释相关的构建错误,在你的app/build中添加以下配置。gradle文件

configurations {
        compile.exclude group: 'com.intellij', module: 'annotations'
        implementation.exclude group: 'com.intellij', module:'annotations'
    } 

我的问题是在统一时创建。abb文件。

我所做的唯一一件事就是取消勾选“分割应用程序二进制”。

我之前的错误是说,安装的构建工具版本33.0.1已损坏。 还有JAVA_TOOL_OPTIONS错误。

我有Gradle 6.1.1(构建.abb),和Android SDK路径(从Android studio安装的)。NDK和SDK我使用统一默认。

我的构建完成得很好。我运行它与脚本后端Mono设置。希望IL2CPP也能起作用。

如果这对你有用,请给我的解决方案投票:)