Reputation: 392
I'm unable to run any tests or run the app or debugger because of this error:
`Unable to find method void org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions.setUseIR(boolean)`
I've tried all of the provided solutions and hit the File > Invalidate Caches/Restart...
option.
This is an Android Studio project in Kotlin and Java with Jetpack Compose, Retrofit2, OkHttp3.
Update: Here are my build.gradle files
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
}
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:+"
}
Here are a bunch more words so that StackOverflow will accept my edits. Too much code you say? Maybe I'm not that great at coding yet and I have way too many dependencies. I don't know what these things do. Sometimes I have an idea, but mostly I'm just reading tutorials and documentation and blindly following whatever they say. Is this enough words yet?
Upvotes: 19
Views: 19345
Reputation: 1234
When I'm using Kotlin version 2.0.0 then i'm facing this issue.
I have changed my KSP
Version "1.9.20-1.0.13" to "2.0.0-1.0.22"
libs.versions.toml
ksp = "2.0.0-1.0.22"
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
Version Compatibility
This chart illustrates the compatibility between Kotlin and Kotlin Symbol Processing (KSP) versions.
Kotlin Version | KSP Version |
---|---|
2.1.10 | 2.1.10-1.0.29 |
2.1.0 | 2.1.0-1.0.29 |
2.0.21 | 2.0.21-1.0.25 |
2.0.20 | 2.0.20-1.0.24 |
2.0.0 | 2.0.0-1.0.22 |
Note
If you are using Dagger Hilt and have updated your Kotlin 2.1.0
and KSP 2.1.0-1.0.29
versions then you need to use Dagger Hilt version 2.53
. Please check your dagger hilt version compatibility also
Upvotes: 26
Reputation: 845
If you still having issues and you installed latest Android studio (LadyBug) and created a new project and wish to use room library you will need to migrate from kapt to ksp. You can read about it here https://developer.android.com/build/migrate-to-ksp Basically you will need to follow the following steps:
add the following line into Project module build.gradle.kts in plugins section
id("com.google.devtools.ksp") version "2.0.21-1.0.27" apply false
add the following line into Module build.gradle.kts in plugins section
id("com.google.devtools.ksp")
you will be required to update the kotlin version in libs.versions.toml from 1.9.24 to 2.0.21 (maybe there will be a newer version by the time you will see this solution, android studio will inform you which version you need to update in the console after syncing the project).
sync the project, it should work after that
Upvotes: 0
Reputation: 23394
Updating com.android.tools.build:gradle
version to 7.0.4
fixed it for me
classpath "com.android.tools.build:gradle:7.0.4"
Upvotes: 8
Reputation: 608
Duplicated kotlin-gradle-plugin
in Project's build.gradle
might mess things up
Upvotes: 7