I am trying to implement compose in multi module project and i am constantly getting following error:
androidx.compose.compiler.plugins.kotlin.IncompatibleComposeRuntimeVersionException: You are using an outdated version of Compose Runtime that is not compatible with the version of the Compose Compiler plugin you have installed. The compose compiler plugin you are using (version 1.0.3) expects a minimum runtime version of 1.0.0. at androidx.compose.compiler.plugins.kotlin.VersionChecker.outdatedRuntimeWithUnknownVersionNumber(VersionChecker.kt:119)
I only have on version specified (1.0.3) for all Compose dependencies, i also tried adding compose compiler to root build.gradle:
dependencies {
implementation "androidx.compose.compiler:compiler:1.0.3"
}
At the root file i also added configuration for compose:
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.0.3'
}
kotlinOptions {
jvmTarget = '1.8'
}
And then in module build.gradle i added compose dependencies (compose ui, material, ui toolign preview and uitooling), i also upgraded gradle to latest 7.0.2 and still same error poping, i checked gradle dependency tree no sign on 1.0.0 compiler anywhere, any idea what else i could try or what am i doing wrong?
Okay so the issue was i had to include activity-compose dependency on root gradle, and with that it works normally (if i try to include it per module it does not work)
Related
All I wanted to do in my Android Native app using Jetpack Compose was to use some of the newer versions of some of the software. I guess I should have known better, because this has turned into the usual dependency nightmare. I have wasted all afternoon trying to get this to compile and run.
I’ll start with the error message, and work backwards:
> Task :app:compileDebugKotlin FAILED
> 'compileDebugJavaWithJavac' task (current target is 17) and 'compileDebugKotlin' task (current target is 1.8) jvm target compatibility should be set to the same Java version.
> e: This version (1.2.0-alpha05) 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!).
First, I have no idea why the compileDebugKotlin thinks I am targeting JVM 1.8 instead of 17. My JAVA_HOME is set to Java 17, my IntelliJ Project Structure JDK is set to 17, and my app:build.gradle has the following:
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
I do not see 1.8 being set anywhere.
The next issue is the Compose Compiler version that the error message is showing, 1.2.0-alpha05. I am setting the following in my root build.gradle file:
buildscript {
ext {
compose_version = '1.3.0'
…
And then referring to it in my app:build.gradle file:
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation "androidx.compose.runtime:runtime-livedata:$compose_version"
implementation "androidx.compose.foundation:foundation:$compose_version"
I have no idea where it’s coming up with 1.2.0-alpha05 as the version.
The next issue is that it thinks I'm using Kotlin 1.7.10. I have set the Kotlin version to 1.6.10 in the IntelliJ preferences for Kotlin compiler, as well as 17 for the JVM. I tried the following in build.gradle, but it seems to be ignored, it is making no difference:
kotlin {
version("1.6.10")
}
In a nutshell, I have no idea where any of these version numbers are coming from, and how to set them so that they reflect the reality that I thought I was configuring correctly. I have cleared the IntelliJ cache and restarted numerous times.
the two task shown in the error have different functions during a build
compileDebugJavaWithJavac is responsible for generating the bytecode for the Java Code and making it available for further processing. which in your case is targeted to java 17 but compileDebugKotlin is responsible for making bytecode for kotlin code in your case it is targeted to 1.8 ,that is not supported so you should add
kotlinOptions {
jvmTarget = '17'
}
composeCompiler is not Compatible with all versions of Kotlin. Each compose compiler has corresponding compatible Kotlin Version (Compose to Kotlin Compatibility Map). what you shown is compose_version which do not represent Compose Compiler, they are declared in
composeOptions {
kotlinCompilerExtensionVersion = "1.x.x"
}
As I introduced Jetpack Compose and Room simultaneously for a new app, my Android Studio threw this error.
/***/***/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.7.0/51736992f422993a1e741051bdf3c12801bc1ca1/kotlin-stdlib-common-1.7.0.jar!/META-INF/kotlin-stdlib-common.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1, expected version is 1.5.1.
When I wrote codes without Room libraries, I didn't get the error.
Here is what I tried to solve this problem.
Upgrading Android Studio and Kotlin version
Referred this page: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15
However, I wasn't able to find "ext.kotlin_version = 'xxx'.", so I wrote this code in build.gradle, but wasn't able to solve it.
buildscript {
ext {
compose_version = '1.1.0-beta01'
kotlin_version = '1.7.0' // add this line with '1.7.0' and '1.7.1'
}
}
Referred another page: https://github.com/square/kotlinpoet/issues/1303
How should I do next to deal with this problem?
You can try upgrading kotlin to 1.7.10 and compose to 1.3.0.
If not worked,try with compose 1.2.0 and kotlin 1.7.0
You can find all compataible versions here.
Also make sure to use same variable for kotlin gradle plugin in project build.gradle.
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
On one project I have used sucesfully argument -XXLanguage:-ProperCheckAnnotationsTargetInTypeUsePositions in kotlinOptions to disable "typeUsage" check on annotations. This project has regular build.gradle in Groovy. However when I have used exactly same approach on same version of Kotlin (1.6.0) in fresh project with Kotlin DSL gradle files (build.gradle.kts) it seems like this argument is ignored totally.
Summarizing:
project with good-old Groovy gradle -> argument works and disable error on "wrong usage of annotations"
project with new Kotlin DSL gradle -> argument seems to be ignored and still produces error
Maybe someone has same issue?
This is connected with Compatibility of android annotations with Kotlin 1.6.0
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = listOf("-XXLanguage:-ProperCheckAnnotationsTargetInTypeUsePositions")
}
After upgrading to jetpack compose 1.0.0-beta01, I tried to use arrayListOf, listOf from kotlin.collections but they seemed to not implicitly imported.
Your problem is probably related to what Kotlin version you are using.
I guess I went through a similar process as
you did when I was updating to the new version of Jetpack Compose library, where
as a "side effect" I was forced to update kotlin and kotlin-gradle-plugin version what then
indirectly caused your (and mine) problem. Following workaround should fix it.
Most likely you are using Kotlin 1.4.30 after updating Jetpack Compose to 1.0.0-beta01. Update Kotlin to fixed 1.4.31 version and your problem will be ALMOST "resolved".
I think the whole problem is somehow related to the following bug in 1.4.30 if
you are more interested https://youtrack.jetbrains.com/issue/KT-44845
Now after trying to build your project you will get a nice error saying This version (1.0.0-alpha13) of the Compose Compiler requires Kotlin version 1.4.30 but you appear to be using Kotlin version 1.4.31 which is not known to be compatible. Please fix your configuration (or `suppressKotlinVersionCompatibilityCheck` but don't say I didn't warn you!).
suppressKotlinVersionCompatibilityCheck is a compile argument which in my case I have set in module build.gradle file under android -> kotlinOptions this way:
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
useIR = true
//here -->
freeCompilerArgs += ["-P", "plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true"]
}
It also depends on the type of build.gradle files.
Read more about how to set those compile arguments at
Configure compiler arguments
where are described different ways for groovy and also for kotlin based gradle files.
Now you should be fine but bear in mind that you want to get rid of the suppressKotlinVersionCompatibilityCheck argument as soon as there is a new version of Jetpack Compose relying on a newer version of Kotlin.
I am trying to set up Android Room in my Jetpack Compose project. However, when trying to add...
kapt "androidx.room:room-compiler:2.2.3"
... to the app build.gradle dependencies. My build fails with the error...
e: java.lang.NoSuchMethodError: org.jetbrains.kotlin.codegen.state.GenerationState$Builder.isIrBackend(Z)Lorg/jetbrains/kotlin/codegen/state/GenerationState$Builder;
Any insight as to why this is? Can we use Android Room with Jetpack Compose yet?
I'm pretty sure that we're still in a state where annotation processors (for Room, Retrofit, etc.) and the experimental Kotlin compiler are not getting along. The recommended approach at the moment is to isolate the Compose stuff in a module that is independent of modules that need annotation processors.
This is currently not supported as kapt does not play well with Jetpack Compose. This issue is being tracked here - https://issuetracker.google.com/issues/143232368
It's actually working, but not without some changes.
For a new project created with AndroidStudio 2020.3.1 Canary 2:
In build.gradle (Project):
Downgrade compose_version to 1.0.0-alpha07 and ext.kotlin_version to 1.4.10.
In build.gradle (Module):
Under composeOptions downgrade the composeCompilerVersion to 1.4.10.
Under dependencies change "androidx.compose.ui:ui-tooling:$compose_version" to "androidx.ui:ui-tooling:$compose_version".
In Main activity - change the import for the preview, as it depends on ui-tooling.
Add room dependencies.
Should work.
However, some newer Compose functionalities won't probably work, as they are explicitly stating, that one should use Kotlin version 1.4.20 and above.