Android Installed Build Tools revision 31.0.0 is corrupted

*该教程为mac环境下*

由于电脑原因重新安装了系统,之后安装android studio跑项目的时候出现如下错误

Installed Build Tools revision 31.0.0 is corrupted. Remove and install again using the SDK Manager.

1、android studio版本为如下:

Android Studio 版本信息

SDK Platforms

SDK Tools

android {
    compileSdkVersion 31
    buildToolsVersion "31.0.0"

    defaultConfig {
        applicationId "com.civiccloud.myapplication"
        minSdkVersion 21
        targetSdkVersion 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

2、错误信息如下:

Executing tasks: [:app:assembleDebug] in project /Users/yau/Downloads/demo

Build-tool 31.0.0 is missing DX at /Users/yau/softSdk/Android/SDK/build-tools/31.0.0/dx
Build-tool 31.0.0 is missing DX at /Users/yau/softSdk/Android/SDK/build-tools/31.0.0/dx

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Installed Build Tools revision 31.0.0 is corrupted. Remove and install again using the SDK Manager.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

3、很显然错误信息告诉我们丢失了dx文件解决方案如下:
1.先找到Android 的安装目录

echo $ANDROID_HOME // /Users/softSdk/Android/SDK

2.修改文件名称

mv /Users/softSdk/Android/SDK/build-toolsd/31.0.0/8 /Users/softSdk/Android/SDK/dx
mv /Users/softSdk/Android/SDK/build-tools/lib/31.0.0/d8.jar /Users/softSdk/Android/SDK/build-tools/31.0.0/lib/dx.jar

至此教程结束

你可能感兴趣的:(Android Installed Build Tools revision 31.0.0 is corrupted)