Home > Enterprise >  Compile and Debug Kotlin FAILED
Compile and Debug Kotlin FAILED

Time:08-16

Today, while working for some unknown reason, the following error occurred:

Task :app:compileDebugKotlin FAILED e: This version (1.1.1) of the Compose Compiler requires Kotlin version 1.6.10 but you appear to be using Kotlin version 1.7.10 which is not known to be compatible. Please fix your configuration (or suppressKotlinVersionCompatibilityCheck but don't say I didn't warn you!). FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:compileDebugKotlin'.

A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction Compilation error. See log for more details

I have encountered this issue once before, but several weeks ago. And I made some tweaks and it worked. Unfortunately, now it is very hard to know exactly where the problem is.

build.gradle

buildscript {
    dependencies {
        classpath('com.google.dagger:hilt-android-gradle-plugin:2.40.1')
    }
    ext {
        compose_version = '1.1.1'
        coroutines = '1.6.4'
        accompanist = '0.24.13-rc' // https://github.com/google/accompanist
        datastore = '1.0.0' // https://developer.android.com/jetpack/androidx/releases/datastore
        room = '2.4.2'
        navigation = '2.5.0'
        lifecycle = '2.5.0' // https://developer.android.com/jetpack/androidx/releases/lifecycle
        material3 = '1.0.0-alpha14' // https://developer.android.com/jetpack/androidx/releases/compose-material3
        work = '2.7.1' // https://developer.android.com/jetpack/androidx/releases/work
        rcview = '1.2.1' // https://developer.android.com/jetpack/androidx/releases/recyclerview
        rcview_select = '1.1.0'
    }
    repositories {
        google()
    }
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.2.2' apply false
    id 'com.android.library' version '7.2.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
    id 'org.jetbrains.kotlin.jvm' version '1.7.10' apply false
    id 'org.jetbrains.kotlin.plugin.serialization' version '1.7.10' apply false
}

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

build.gradle(:app)

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'dagger.hilt.android.plugin'
    id 'org.jetbrains.kotlin.plugin.serialization'
}

android {
    compileSdk 32

    defaultConfig {
        applicationId ""
        minSdk 24
        targetSdk 32
        versionCode 1
        versionName "0.8.3"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary true
        }
        javaCompileOptions {
            annotationProcessorOptions {
                arguments  = [
                        "room.schemaLocation":"$projectDir/schemas".toString(),
                        "room.incremental":"true",
                        "room.expandProjection":"true"
                ]
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        freeCompilerArgs  = [
                "-opt-in=kotlin.RequiresOptIn"]
        jvmTarget = '1.8'
    }
    buildFeatures {
        compose true
        viewBinding true
    }
    composeOptions {
        kotlinCompilerExtensionVersion "1.1.1"
    }
    packagingOptions {
        resources {
            excludes  = '/META-INF/{AL2.0,LGPL2.1}'
        }
    }
}

dependencies {

    implementation "com.github.ireward:compose-html:1.0.2"
    implementation 'com.google.dagger:hilt-android:2.43.1'
    implementation "androidx.hilt:hilt-navigation-compose:1.0.0"
    kapt 'com.google.dagger:hilt-compiler:2.43.1'

    implementation "androidx.datastore:datastore-preferences:$datastore"
    implementation "androidx.datastore:datastore:1.0.0"
    implementation "org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.5"
    implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2"

    // Coroutines
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines"

    // Work
    implementation "androidx.work:work-runtime-ktx:$work"
    implementation "androidx.work:work-gcm:$work" // optional - GCMNetworkManager support
    androidTestImplementation "androidx.work:work-testing:$work" // optional - Test helpers
    implementation "androidx.work:work-multiprocess:$work" // optional - Multiprocessor support


    // optional - Paging 3 Integration
    implementation "androidx.room:room-paging:2.5.0-alpha02"

    // Navigation
    implementation "androidx.navigation:navigation-fragment-ktx:$navigation"
    implementation "androidx.navigation:navigation-ui-ktx:$navigation"

    implementation "androidx.navigation:navigation-dynamic-features-fragment:$navigation"

    // Testing Navigation
    androidTestImplementation "androidx.navigation:navigation-testing:$navigation"

    // Jetpack Compose Integration
    implementation "androidx.navigation:navigation-compose:$navigation"

    // status bar customization
    implementation "com.google.accompanist:accompanist-systemuicontroller:0.23.1"

    // Accompanist
    implementation "com.google.accompanist:accompanist-pager:$accompanist" // Pager
    implementation "com.google.accompanist:accompanist-pager-indicators:$accompanist" // Pager Indicators
    implementation "com.google.accompanist:accompanist-flowlayout:$accompanist"
    implementation "com.google.accompanist:accompanist-navigation-animation:$accompanist"
    implementation "com.google.accompanist:accompanist-swiperefresh:$accompanist"

    implementation "androidx.recyclerview:recyclerview:$rcview"
    // For control over item selection of both touch and mouse driven selection
    implementation "androidx.recyclerview:recyclerview-selection:$rcview_select"

    // Card view
    implementation "androidx.cardview:cardview:1.0.0"

    // Room:
    implementation("androidx.room:room-runtime:$room")
    annotationProcessor("androidx.room:room-compiler:$room")

    // optional - Kotlin Extensions and Coroutines support for Room
    implementation("androidx.room:room-ktx:$room")

    // optional - RxJava2 support for Room
    implementation("androidx.room:room-rxjava2:$room")

    // optional - RxJava3 support for Room
    implementation("androidx.room:room-rxjava3:$room")

    // optional - Guava support for Room, including Optional and ListenableFuture
    implementation("androidx.room:room-guava:$room")

    // optional - Test helpers
    testImplementation("androidx.room:room-testing:$room")

    // optional - Paging 3 Integration
    implementation("androidx.room:room-paging:2.5.0-alpha02")

    // Google Sign In Integration
    implementation "com.google.android.gms:play-services-auth:20.2.0"

    implementation 'androidx.core:core-ktx:1.8.0'
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.animation:animation-graphics:$compose_version"
    implementation "androidx.compose.material3:material3:$material3"
    implementation "androidx.compose.material3:material3-window-size-class:$material3"
    implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"

    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle"
    implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle"
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle"
    implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle"
    kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle"

    // optional - helpers for implementing LifecycleOwner in a Service
    implementation "androidx.lifecycle:lifecycle-service:$lifecycle"

    // optional - ProcessLifecycleOwner provides a lifecycle for the whole application process
    implementation "androidx.lifecycle:lifecycle-process:$lifecycle"

    // optional - ReactiveStreams support for LiveData
    implementation "androidx.lifecycle:lifecycle-reactivestreams-ktx:$lifecycle"

    // optional - Test helpers for LiveData
    testImplementation "androidx.arch.core:core-testing:2.1.0"

    // optional - Test helpers for Lifecycle runtime
    testImplementation "androidx.lifecycle:lifecycle-runtime-testing:$lifecycle"

    implementation "androidx.fragment:fragment-ktx:1.5.1"
    implementation "androidx.activity:activity-ktx:1.5.1"

    // https://github.com/Bryanx/themed-toggle-button-group
    implementation "nl.bryanderidder:themed-toggle-button-group:1.4.1"

    implementation 'androidx.activity:activity-compose:1.5.0'
    testImplementation 'junit:junit:4.13.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"
    debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
    debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
}

Confusing part: Kotlin version 1.6.10 but you appear to be using Kotlin version 1.7.10

CodePudding user response:

I use 1.3.0-alpha02 with project gradle file as

buildscript {
    ext {
        compose_version = '1.3.0-alpha02'
    }
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.2.1' apply false
    id 'com.android.library' version '7.2.1' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
}

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

app module gradle file

android {
    // Rest ...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion '1.2.0'
    }

}

But your error log says you should change

id 'org.jetbrains.kotlin.jvm' version '1.7.10' apply false 

to

id 'org.jetbrains.kotlin.android' version '1.6.10' apply false

for Compose version 1.1.1 but latest stable version is 1.2.1 you can update your version if there is no version constraint to it then update other dependencies according to that.

  • Related