无法找到方法 void org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions.setUseIR(boolean)

pet*_*art 14 java gradle kotlin android-studio okhttp

我无法运行任何测试或运行应用程序或调试器,因为this error:

`Unable to find method void org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions.setUseIR(boolean)`
Run Code Online (Sandbox Code Playgroud)

我已经尝试了所有提供的解决方案并点击了该File > Invalidate Caches/Restart...选项。

在此输入图像描述

这是一个使用 Kotlin 和 Java 编写的 Android Studio 项目,包含 Jetpack Compose、Retrofit2、OkHttp3。


更新:这是我的 build.gradle 文件

build.gradle项目:

buildscript {
    ext.kotlin_version = '1.6.0-RC'
    ext {
        compose_version = '1.0.1'
        fragment_version = "1.3.6"
    }
    repositories {
        google()
        mavenCentral()
        maven {
            url = uri("https://plugins.gradle.org/m2/")
        }
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.2"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"
        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
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)

构建.gradle应用程序:

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id("org.jetbrains.kotlin.android.extensions")
}

android {
    compileSdk 31

    useLibrary("android.test.runner")
    useLibrary("android.test.base")
    useLibrary("android.test.mock")

    defaultConfig {
        applicationId "com.example.moviespotter"
        minSdk 21
        targetSdk 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary true
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    buildFeatures {
        viewBinding = true
        compose true
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    composeOptions {
        kotlinCompilerExtensionVersion compose_version
        kotlinCompilerVersion '1.5.21'
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
        kotlinOptions {
            jvmTarget = '1.8'
        }
    }
    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
        }
    }
}

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.0.4'
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.material:material:$compose_version"
    implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
    implementation 'androidx.activity:activity-compose:1.3.1'
    implementation 'androidx.test.espresso:espresso-idling-resource:3.1.1'
    testImplementation 'junit:junit:4.13'
    testImplementation("com.squareup.okhttp3:mockwebserver:4.9.2")
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
    androidTestImplementation 'androidx.test:rules:1.4.0'
    androidTestImplementation 'androidx.test:runner:1.4.0'
    debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
    implementation 'com.squareup.retrofit2:retrofit:2.7.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.7.0'
    implementation 'com.squareup.okhttp3:okhttp:4.3.1'
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'com.github.bumptech.glide:glide:4.10.0' //Glide
    implementation "androidx.fragment:fragment-ktx:$fragment_version"
    implementation "androidx.fragment:fragment-ktx:$fragment_version"
    implementation "io.coil-kt:coil-compose:1.3.1"
    annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
    implementation "androidx.core:core-ktx:+"
}
Run Code Online (Sandbox Code Playgroud)

这里还有一些文字,以便 StackOverflow 接受我的编辑。你说的代码太多了?也许我还不太擅长编码,而且我有太多的依赖项。我不知道这些东西是做什么的。有时我有一个想法,但大多数时候我只是阅读教程和文档并盲目遵循他们所说的。话已经够多了吗?

Man*_*ddy 8

更新com.android.tools.build:gradle版本来7.0.4为我修复它

classpath "com.android.tools.build:gradle:7.0.4"
Run Code Online (Sandbox Code Playgroud)


out*_*ing 6

kotlin-gradle-plugin在项目中重复build.gradle可能会把事情搞砸