Android Navigation 2.4.0-rc01与Jetpack Compose不兼容。

3

想要升级导航版本到2.4.0-rc01,但在进行升级时遇到了以下错误:

This version (1.0.5) of the Compose Compiler requires Kotlin version 1.5.31 but you appear to be using Kotlin version 1.6.0 which is not known to be compatible.

有人成功让这个工作了吗?

编辑:我的 build.gradle

项目:

buildscript {
    ext {
        kotlin_version = '1.5.31'
        navigation_version = '2.4.0-rc01'
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.4'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigation_version"
        classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
    }
}

App

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-parcelize'
    id 'kotlin-kapt'
    id 'androidx.navigation.safeargs.kotlin'
    id 'dagger.hilt.android.plugin'
    id 'com.google.secrets_gradle_plugin' version '0.4'
}

android {
    signingConfigs {
        debug {
            storeFile file('C:\\Users\\olive\\.android\\debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
    }
    compileSdkVersion 31
    buildToolsVersion "29.0.3"
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8.toString()
    }
    buildFeatures {
        viewBinding true
        dataBinding true
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion '1.0.5'
        kotlinCompilerVersion '1.5.31'
    }
}

顺便提一下,我看到kotlinCompilerVersion已被弃用。不确定是否有影响,但仍然收到相同的消息。


你应该分享 build.gradle 的内容。 - Sercan Sebetçi
抱歉,已经添加了它们。 - Oliver Song
https://developer.android.com/jetpack/androidx/releases/compose-kotlin - P-RAD
4个回答

0

我认为这与Navigation Lib无关。

从您分享的构建错误来看,您只需要在项目的gradle文件classpath中更改Kotlin版本为version 1.5.31

项目build.gradle

buildscript {
    ext {
        compose_version = '1.0.5'
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.4"

        //here use Kotlin version 1.5.31
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"
  
       
    }
}

你也可以在 gradle.build 应用文件中指定 Kotlin 版本。 build.gradle(app) 文件
 compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
        useIR = true
    }
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion compose_version
        //Make this version 1.5.31
        kotlinCompilerVersion '1.5.31'

谢谢您的建议!我尝试了一下,但即使在清除缓存后,仍然出现相同的错误。 - Oliver Song

0

在我的情况下,我使用这个 build.gradle root

 ext {
        compose_version = '1.0.5'
        kotlin_version = '1.5.31'
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.3"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"

        classpath 'com.google.gms:google-services:4.3.10'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

然后 构建.gradle应用程序文件夹

 composeOptions {
        kotlinCompilerExtensionVersion compose_version
    }
dependencies {
   //navigation
    // Jetpack Compose Integration
    implementation 'androidx.navigation:navigation-compose:2.4.0-rc01'

0

如果您正在使用稳定的Compose版本,那么您应该同时使用稳定版本的导航,反之亦然。否则,如果您使用预览版,则可以使用Kotlin 1.6等版本和Compose预览版 :)


0

使用 safeargs 插件是导致问题的原因,插件版本 2.4.0-rc01 使用 kotlin 1.6。 但我没有找到在使用时强制使用 kotlin 插件版本的方法。


啊,我明白了。我最终将我的Jetpack Compose编译器升级到1.1.0-rc02版本,这个版本与1.6兼容。 - Oliver Song

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接