检查模块类路径是否缺少 gradle 版本 7.0.1 或存在冲突的依赖项

Pus*_*dra 5 data-binding android gradle kotlin android-viewbinding

我被这个问题困住了。我已将项目等级升级到 7.0.1 和 Kotlin 1.5.30。升级之前一切正常。但升级后,我开始为每个项目收到以下错误。甚至,我也尝试过创建新项目。我也面临着同样的问题。请检查下图。 在此输入图像描述

下面,我正在编写我的项目的所有文件。其中负责数据绑定和视图绑定。

项目基础build.gradle

buildscript {
  ext.kotlin_version = '1.5.30'
  repositories {
      google()
      mavenCentral()
  }
  dependencies {
      classpath "com.android.tools.build:gradle:7.0.1"
      classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
  }
}
task clean(type: Delete) {
  delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)

基于应用程序的 build.gradle 文件

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

android {
    compileSdk 30

    defaultConfig {
        applicationId "colour.moon"
        minSdk 21
        targetSdk 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_11
        targetCompatibility JavaVersion.VERSION_11
    }
    kotlinOptions {
        jvmTarget = '11'
    }

    buildFeatures {
        dataBinding true
        viewBinding true
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.6.0'
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
}
Run Code Online (Sandbox Code Playgroud)

settings.gradle 文件这里这个文件自动包含给定的代码。我想把它放在这里以便于理解

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}
rootProject.name = "My Application"
include ':app'

Run Code Online (Sandbox Code Playgroud)

这是产生错误的主文件。请仔细检查。

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">
    <data>
        <variable
            name="viewModel"
            type="colour.moon.MainVM" />
    </data>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World!"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Run Code Online (Sandbox Code Playgroud)

当我将我的视图转换为时,layout就会出现上述错误。请告诉我,如何解决?如果我们需要删除布局,那么如何在 XML 文件中使用数据绑定!

我将非常感谢您的回答!