Gradle 同步失败:无法初始化类 org.jetbrains.kotlin.gradle.internal.KotlinSourceSetProviderImplKt

Deg*_*mar 0 android gradle kotlin android-studio

21:10   Gradle sync failed: Could not initialize class org.jetbrains.kotlin.gradle.internal.KotlinSourceSetProviderImplKt
            Consult IDE log for more details (Help | Show Log) (7s 78ms)
Run Code Online (Sandbox Code Playgroud)

嗨,伙计们,我试图使缓存无效并重新启动,将项目与 gradle 和文件系统同步,更新最新的稳定 kotlin,创建新项目并让 android studio 下载所有更新,但仍然遇到同样的错误。谁能帮我 ?对不起,我真的是安卓的新手

这是我的= app/build.gradle

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "com.asusx.rogmode.rog"
        minSdkVersion 27
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:29'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Run Code Online (Sandbox Code Playgroud)

gradle-wrapper.properties

#Wed Jun 10 20:24:06 ICT 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
Run Code Online (Sandbox Code Playgroud)

构建.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.2.30'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.0'
        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
}
Run Code Online (Sandbox Code Playgroud)

小智 6

当我将 Android Studio 从 3.5 更新到 4.0 时,我遇到了同样的问题。

我将 ext.kotlin_version 更改为 1.3.72,然后运行构建。这解决了问题。

这个链接给了我提示:https : //kotlinlang.org/docs/reference/using-gradle.html