Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrading Android kotlin version to 1.5.0 throwing error message on build

Tags:

android

kotlin

Running with kotlin version '1.4.32' my Android project runs and builds. Trying to upgrade to kotlin '1.5.0' and my build throws:

Execution failed for task ':app:kaptDefaultsDebugKotlin'. > A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction    > java.lang.reflect.InvocationTargetException (no error message) 

I am not even sure where to start looking. Anyone else have problems upgrading to kotlin 1.5.0?

like image 867
lostintranslation Avatar asked May 06 '21 02:05

lostintranslation


People also ask

Is Kotlin 1.5 stable?

The Android Kotlin compiler produces Java 8 bytecode by default (which runs in any later JVM), but lets the programmer choose to target Java 9 up to 18, for optimization, or allows for more features; has bidirectional record class interoperability support for JVM, introduced in Java 16, considered stable as of Kotlin ...

In which file do we change the version of Kotlin in Android app?

Select your module in the Project window, and then select File > New, select any Android template, and then choose Kotlin as the Source language.


2 Answers

I experienced the same issue today. Ran the gradle build command with --stacktrace and got a helpful stacktrace which narrowed down the issue to Moshi library.

Caused by: java.lang.IllegalStateException: Could not parse metadata! This should only happen if you're using Kotlin <1.1.     at com.squareup.moshi.kotlinpoet.metadata.KotlinPoetMetadata.readKotlinClassMetadata(KotlinPoetMetadata.kt:70)     at com.squareup.moshi.kotlinpoet.metadata.KotlinPoetMetadata.toImmutableKmClass(KotlinPoetMetadata.kt:50)     at com.squareup.moshi.kotlin.codegen.MoshiCachedClassInspector.toImmutableKmClass(MoshiCachedClassInspector.kt:22)     at com.squareup.moshi.kotlin.codegen.MetadataKt.targetType(metadata.kt:109)     at com.squareup.moshi.kotlin.codegen.JsonClassCodegenProcessor.adapterGenerator(JsonClassCodegenProcessor.kt:136)     at com.squareup.moshi.kotlin.codegen.JsonClassCodegenProcessor.process(JsonClassCodegenProcessor.kt:110)     at org.jetbrains.kotlin.kapt3.base.incremental.IncrementalProcessor.process(incrementalProcessors.kt:90)     at org.jetbrains.kotlin.kapt3.base.ProcessorWrapper.process(annotationProcessing.kt:175)     at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:980)     ... 41 more 

Had to update Moshi to 1.12.0 and that did the trick.

Here's a changelog for Moshi 1.12.0 that mentions the fix for 1.5.0: https://github.com/square/moshi/blob/master/CHANGELOG.md#version-1120

Issue when it was first reported here: https://github.com/square/moshi/issues/1324

Another issue which mentions the fix here: https://github.com/square/moshi/issues/1337

So I'd suggest you run gradle build command with --stacktrace and figure out which library causes the incompatibility with the kotlinx-metadata-jvm library and update it.

like image 101
avatsav Avatar answered Sep 20 '22 14:09

avatsav


This is due to Dagger's use of older version of kotlinx-metadata-jvm. See https://youtrack.jetbrains.com/issue/KT-45885

Update your dagger to 2.34

like image 38
Etherbit Avatar answered Sep 18 '22 14:09

Etherbit