Android Gradle 同步 "Tag Mismatch!" 错误

Android Gradle Sync "Tag Mismatch!" error

过去 3 天我无法解决 Android Gradle 同步“标签不匹配!”错误。我查看并搜索了许多解决方案,但 none 给出了肯定的输出。 我还重新安装了 android studio 并重新下载了 SDK,但都是在静脉中。

如果有人知道如何解决这个错误,请告诉我

ps,我附上了下图,我使用的是Android Studio 4.1.3版本

Gradle 同步标记不匹配错误

Build.gradle(应用程序)

plugins {
id 'com.android.application'
id 'kotlin-android'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

defaultConfig {
    applicationId "com.example.testsample"
    minSdkVersion 16
    targetSdkVersion 30
    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
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.2.0'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android.material:material:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

Build.gradle(项目)

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = "1.3.72"
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.1.3"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

可能是 Gradle 下载不完整。转到 .gradle 文件夹(对我来说它在用户文件夹中)并删除 /wrapper/dists/ 下的文件。尝试重新下载 gradle。

原来卡巴斯基的安全通道阻止了 android studio 组件的完整下载。

禁用您的 Kaspersky,安装您的 android studio 并让您的组件成功下载。

我的电脑上没有安装卡巴斯基,在使用其他人的代码或使用 GitHub 时出现此错误。

我在网上看到这个答案,但是我当时想不起来link是什么了。

基本上你需要:

  1. 转到您的 build-tools 安装文件夹

    在 Windows,这是在 C:\Users\YourUsername\AppData\Local\Android\Sdk\build-tools\{build tools version}

  2. 现在您需要复制 d8.bat 文件并将副本重命名为 dx.bat
  3. 然后您需要将 d8.jar 文件复制到 lib 文件夹并将其重命名为 dx.jar

在 Windows,这是在 C:\Users\{YourUsername}\AppData\Local\Android\Sdk\build-tools\{build tools version}\lib

项目 *** 在 运行 Gradle 时使用以下 JDK 位置: H:/程序Files/Java/jdk1.8.0_281 在不同的进程上使用不同的 JDK 位置可能会导致 Gradle 产生多个守护进程,例如,通过从终端执行 Gradle 任务 使用 Android Studio 时。

在我将 JDK 位置更改为 Android Studio 默认值之后 Gradle 同步“标签不匹配!”错误出来了...... 我google呢,还是不知道为什么。 所以我必须将项目 JDK 位置改回来,没有“标签不匹配”, 但警告“在不同进程中使用不同的 JDK 位置” enter image description here