Android Navigation 2.4.0-rc01 incompatible with Jetpack Compose

Viewed 552

Wanted to upgrade navigation version to 2.4.0-rc01, but I get this error when I do so

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.

Anybody managed to get this to work?

Edit: My build.gradle

Project:

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'
    }
}

On a side note, I see that kotlinCompilerVersion is deprecated. Not sure if that's affecting anything, but still getting the same message.

4 Answers

I don't think this has anything to do with theNavigation Lib.

From the build error that you have shared you only need to change Kotlin's Version in the project's gradle file classpath to version 1.5.31.

project 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"
  
       
    }
}

You can also specify Kotlin version on the gradle.build App file.

build.gradle(app) file

 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'

in my case I use this 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
    }

then build.gradle app folder

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

Using the safeargs plugin is what's causing the issue, the version 2.4.0-rc01 of the plugin uses kotlin 1.6. I didn't find a way to enforce the kotlin's plugin version when using it though

if you are using a stable compose version, you should be using the stable version of navigation as well and vice versa otherwise if you use the preview you can use Kotlin 1.6 for example and compose preview version :)

Related