首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >编译和调试Kotlin失败

编译和调试Kotlin失败
EN

Stack Overflow用户
提问于 2022-08-16 10:05:52
回答 1查看 237关注 0票数 1

今天,由于一些未知的原因而工作时,发生了以下错误:

任务:app:编译程序失败e:这个版本(1.1.1)的复合编译器需要Kotlin版本1.6.10,但是您似乎使用的是Kotlin版本1.7.10,这并不是已知的兼容版本。请修复您的配置(或suppressKotlinVersionCompatibilityCheck,但不要说我没有警告您!)失败:生成失败,出现异常。

问题所在:任务':app:compileDebugKotlin'.的执行失败

执行org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction编译错误时发生了

失败。有关详细信息,请参阅日志。

我以前见过一次这个问题,但几个星期前。我做了些调整,结果成功了。不幸的是,现在很难确切知道问题出在哪里。

build.gradle

代码语言:javascript
运行
复制
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)

代码语言:javascript
运行
复制
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"
}

混淆部分:Kotlin版本1.6.10,但您似乎使用的是Kotlin版本1.7.10

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-16 10:16:10

我将1.3.0-alpha 02与项目分级文件一起用作

代码语言:javascript
运行
复制
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模块级文件

代码语言:javascript
运行
复制
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'
    }

}

但是您的错误日志显示您应该更改

代码语言:javascript
运行
复制
id 'org.jetbrains.kotlin.jvm' version '1.7.10' apply false 

代码语言:javascript
运行
复制
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false

对于编写版本1.1.1,但最新的稳定版本是1.2.1,如果没有版本约束,您可以更新版本,然后根据此更新其他依赖项。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73372239

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档