此版本(1.1.1)的合成编译器需要Kotlin1.6.10版,但您使用的似乎是Kotlin 1.5.31版

e0bqpujr  于 2022-11-16  发布在  Kotlin
关注(0)|答案(6)|浏览(266)

我使用的是最新的Android Studio,将compose_version设置为1.0.5时,我可以很好地构建和运行我的应用。但是,我想使用最新的稳定合成版本1.1.1
我尝试简单地更新项目build.gradle,使其包含指向所需compose版本和相应兼容Kotlin版本的以下内容。这些值在应用的build.gradle中引用。

buildscript {
    ext {
        compose_version = '1.1.1'
        kotlin_version = '1.6.10'
    }

在Android Studio中,我会转到工具〉Kotlin〉配置Kotlin插件更新,然后下载最新的Kotlin插件(抢先体验)。
如果我打开“工具”〉“Kotlin”〉“Kotlin REPL”,我会看到Welcome to Kotlin version 1.7.0-RC2-release-258 (JRE 11.0.12+0-b1504.28-7817840)
现在,我尝试重建项目。
我得到错误:This version (1.1.1) of the Compose Compiler requires Kotlin version 1.6.10 but you appear to be using Kotlin version 1.5.31 which is not known to be compatible. Please fix your configuration (or suppressKotlinVersionCompatibilityCheck but don't say I didn't warn you!).
我不希望suppressKotlinVersionCompatibilityCheck给出警告,但我甚至尝试了该选项,并得到其他构建错误。
为什么要使用Kotlin1.5.31版?更新Kotlin插件是否应该让Android Studio切换到更新的Kotlin版本(如Kotlin REPL消息所示)?如何才能使Kotlin 1.6.10版在使用时不再出现错误?

f1tvaqid

f1tvaqid1#

Compose使用buildscript块中定义的Kotlin编译器:

buildscript {
   ext.kotlin_version = '1.6.10'
   //....
   dependencies {
       classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
   }
}

如果在settings.gradlebuild.gradle中使用plugins块:

pluginManagement {

    plugins {
        id 'org.jetbrains.kotlin.android' version '1.6.10' 
    }
}
7kjnsjlb

7kjnsjlb2#

使用Compose 1.1.1.和Kotlin1.7.0时出现相同的错误。
任务:应用程序:编译调试Kotlin失败e:此版本(1.1.1)的Compose Compiler需要Kotlin版本1.6.10,但您使用的Kotlin版本1.7.0不兼容。请修正您的配置(或suppressKotlinVersionCompatibilityCheck,但不要说我没有警告过您!)。
更改了我的**build.gradle(应用模块)**中的以下块

composeOptions {
    kotlinCompilerExtensionVersion 1.2.0
}

这是我在build.gradle(项目)中的插件块:

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.6.21' apply false
    id 'org.jetbrains.kotlin.jvm' version '1.7.0' apply false
}

这个Android开发者页面帮助选择兼容的版本:-
Compose to Kotlin Compatibility Map
不要忘记同步和重建。

s6fujrry

s6fujrry3#

用这个帮我。
build.gradle (:app)

composeOptions {
    kotlinCompilerExtensionVersion = "1.2.0-beta03"
}
btxsgosb

btxsgosb4#

buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:7.1.3'
    }
}

plugins {
    id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
}

和build.gradle(模块)

composeOptions {
    kotlinCompilerExtensionVersion '1.1.1'
}
8yoxcaq7

8yoxcaq75#

有3件事你需要确保是在同步(兼容其他)的Kotlin正常工作。
1)build.gradle中构建脚本的compose_ui_version =“1.2.1”(项目)
2)插件“org.jetbrains.kotlin.android”版本“1.7.10”在build.gradle中(项目)
3)kotlinCompilerExtensionVersion“1.3.1”在构成中构建.gradle(应用程序)中的选项
要获取compose编译器的最新版本及其相应的Kotlin版本,请查看此处。

ecr0jaav

ecr0jaav6#

对我来说,我必须编辑的是找到build graddle(项目):
1.首先加载compose_version以查看最新的稳定compose_version。

buildscript {
    ext {
        //2. change here to the latest stable (compose_version) that you got in step 1
        compose_version = '1.3.0'
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
       //when you run you app, The next error will tell you the version of Kotlin that the latest compose_version needs, edit as below to the version required in the error
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10'
    
    
    }

相关问题