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"
}
Related
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)
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.
Yesterday I updated Android Studio Version and Kotlin plugin version.
Android Studio Version: 3.1.2
Kotlin Version: 1.2.41
When I create an Android project using this configuration, I get Kotlin Compiler warning saying
w: /home/ganeshtikone/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jre7/1.2.41/9e7a6f582de73d9cdc6c56ef4e23604a0ee55768/kotlin-stdlib-jre7-1.2.41.jar: kotlin-stdlib-jre7 is deprecated. Please use kotlin-stdlib-jdk7 instead
Changed as per suggestion, then I am getting following error
Unexpected inputs: ImmutableJarInput{name=org.jetbrains.kotlin:kotlin-stdlib-jre7:1.2.41, file=/home/ganeshtikone/Workspace/May-2018/fhs/app/build/intermediates/transforms/desugar/stage/debug/45.jar, contentTypes=CLASSES, scopes=EXTERNAL_LIBRARIES, status=REMOVED}
Go to Tools > Kotlin > Configure Kotlin Plugin Updates and check for updates
then in your app gradle file replace jre with jdk
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Update
Newer version is jdk8
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
Important Update
Must check JDK version before setting config
Kotlin gradle config page has detailed information about this.
First of all check your kotlin version in gradle file.
if (kotlin_version == '1.2.x' ) (Use jdk NOT jre)
First check your jdk version in File > Project Structure.
Or check in build.gradle
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
if (jdk_version == 1.8)
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
if (jdk_version == 1.7)
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
if (jdk_version is < 1.7)
implementation"org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
else if(NO jdk version is set in Project Structure)
if(Android_Studio_Version < 2.2.1){
your_jdk_version = 1.7;
}
else {
your_jdk_version = 1.8;
}
Because Android Studio is bundled with jdk 1.8 since 2.2.1 version.
2. else if ( kotlin_version == '1.1.x') (Use jre NOT jdk)
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" // or jre8
Update Kotlin Version?
You can update Kotlin version from Tools > Kotlin > Configure Kotlin Updates
Something is transitively importing those libraries. Run Gradle task dependencies to figure out what.
In my case, it was io.vertx:vertx-lang-kotlin-coroutines:3.5.1.
If there is no update for the dependency, there is not much you can do about it
After reading Kotlin Gradle Script Topic
I find out that some ponits
If you're targeting JDK 7 or JDK 8, you can use extended versions of the Kotlin standard library which contain additional extension functions for APIs added in new JDK versions. Instead of kotlin-stdlib, use one of the following dependencies:
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7"
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
I used implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" in my project. I think it's because of compileOptions set in build.graddle
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
You must swap the codes below:
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
Not jre > jdk
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Change SDK7 to Java SDK8
try this:
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}
I have Android Room Persistence library in project(version 1.0.0) and set compile options to 1.8. When project build finishes, i get this warning:
Warning:Supported source version 'RELEASE_7' from annotation processor 'android.arch.persistence.room.RoomProcessor' less than -source '1.8'
Everything works fine, but this warning annoys me. How to remove it?
Adding this dependency dosn't remove warning and i don't use another architecture components.
"android.arch.lifecycle:common-java8:1.0.0"
(Note: this answer is relevant to Kotlin based gradle projects that use the 'kotlin-kapt' plugin (kotlin annotation processor plugin), but should also be useful to Java based projects.)
This warning seems to be fixed in the latest version of the Room library.
I replaced:
kapt "android.arch.persistence.room:compiler:1.0.0"
with
kapt "android.arch.persistence.room:compiler:1.1.0-alpha1"
and the warning went away.
BTW, for Kotlin projects, the warning message varies with the Kotlin version.
With Kotlin 1.1.0 it's:
warning: Supported source version 'RELEASE_7' from annotation processor 'android.arch.persistence.room.RoomProcessor' less than -source '1.8'
but with Kotlin 1.2.21 it's:
warning: Supported source version 'RELEASE_7' from annotation processor 'org.jetbrains.kotlin.kapt3.ProcessorWrapper' less than -source '1.8'
The fix was the same in both cases.
Everything works fine, but this warning annoys me. How to remove it?
Well, You need to disable lint check temporary (Not recommended), by adding these lines into build.gradle:-
android {
lintOptions {
tasks.lint.enabled = false
}
...
}
Adding "android.arch.lifecycle:common-java8:1.0.0" will remove warnings for lifecycle not for room.
By the way, this is just a warning not an error. Ignore it until Google decides to support Java 8 like they did in lifecycle library.
Updating room version from 1.0.0 to 1.1.0 gets rid of the warning.
So just have these following dependencies.
dependencies {
def room_version = "1.1.0"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
}
replaced:
"android.arch.persistence.room:compiler:1.0.0"
with
"android.arch.persistence.room:compiler:1.1.1"
i have the same issue, but i fixed it by
replace
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0'
to
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0'
When I enable the Jack compiler in Android Studio 2.2 the Dagger 2 component is not generated. Can Dagger 2 be used with Jack? If so, how would I go about configuring my application?
From my application's build.gradle:
jackOptions {
enabled true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
I sunk like 2 days into figuring this out. So I'm circling back to posting the findings here in case it saves someone time:
This is caused by a bug in Jack that prevents classpaths from working properly. It has to do with Jack running "in-process" (in the same JVM as the gradle daemon). Setting android.defaultConfig.jackOptions.jackInProcess to false does get beyond the "Preconditions" error but it causes other problems (2 JVMs that hog system resources) & bugs that break the build in other (worse) ways.
For now, the best solution seems to be:
Wait for the 2.3 release of the Android gradle plugin, which already has the fix for this.
Downgrade Dagger to v2.2, in the meantime.
It's the highest version that seems to avoid the Guava conflict with Jack.
EDIT: update 1/14/2017:
I ran into several OTHER problems with Jack and got so tired of it that I switched to retrolambda and kicked myself for not doing this earlier! Right now, Jack simply seems to cause more problems than it solves. Just add the lines with a plus and delete the lines with a minus and you can return to Dagger 2.8 while waiting for Jack to get it's act together!
+plugins {
+ id "me.tatarka.retrolambda" version "3.4.0"
+}
apply plugin: 'com.android.application'
+apply plugin: 'me.tatarka.retrolambda'
- jackOptions {
- enabled true
- }
For even faster retrolambda builds, add org.gradle.jvmargs=-Xmx4608M to your gradle.properties file so that dexing can happen in-process. Now, I'm on Dagger 2.8 and my clean builds are only 12 seconds, GOOD RIDDANCE, JACK!
The documentation page on Jack and Jill has instructions specific to annotation processors "to be applied at compile time but not to be included in your APK", advising the use of the annotationProcessor dependency scope. The example coincidentally mentions Dagger 2:
dependencies {
compile 'com.google.dagger:dagger:2.0'
annotationProcessor 'com.google.dagger:dagger-compiler:2.0'
}
Jack is now deprecated, see this post.
You have to upgrade your Android Studio to 3.0 preview 1, to be able to use Java 8.
If you can't upgrade it (conflict with other lib), or you want to wait for a release version, you can try this workaround solution :
Add the retrolamba lib, follow instructions here.