Kotlin Compiler Plugin for Android causes compilation issue
rolandsarosy-fizetesipont opened this issue · comments
Gradle Version
8.0
AGP Version
8.1.1
Code Minifier/Optimizer
None
Version
3.12.0
Sentry SDK Version
6.33.0
Steps to Reproduce
- Have the following project setup: Kotlin, targetSDK 34, minSDK 21, compose enabled, source/targetCompatibility 17.
- Install the plugin and SDK confirm it is working.
- Add the 3.14.0 version of the Sentry Kotlin Compiler plugin for automatically tagging composable functions.
- Rebuild the project.
Expected Result
Expected result would be that the compilation successfully completes and we have a working implementation of automatic composable tagging.
Actual Result
The actual result is that the application refuses to compile after enabling the compiler plugin. Here is the build output:
Internal compilation error @ app:compileStagingDebugKotlin
A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
java.lang.NoSuchMethodError: 'org.jetbrains.kotlin.ir.declarations.IrVariable org.jetbrains.kotlin.ir.builders.ExpressionHelpersKt.irTemporary$default(org.jetbrains.kotlin.ir.builders.IrStatementsBuilder, org.jetbrains.kotlin.ir.expressions.IrExpression, java.lang.String, org.jetbrains.kotlin.ir.types.IrType, boolean, org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin, int, java.lang.Object)' at io.sentry.compose.JetpackComposeTracingIrExtension$generate$transformer$1.visitFunctionNew(JetpackComposeTracingIrExtension.kt:149) at org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext.visitFunction(IrElementTransformerVoidWithContext.kt:83) at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitSimpleFunction(IrElementTransformerVoid.kt:72) at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitSimpleFunction(IrElementTransformerVoid.kt:73) at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitSimpleFunction(IrElementTransformerVoid.kt:24) at org.jetbrains.kotlin.ir.declarations.IrSimpleFunction.accept(IrSimpleFunction.kt:36) at org.jetbrains.kotlin.ir.IrElementBase.transform(IrElementBase.kt:24) at org.jetbrains.kotlin.ir.util.TransformKt.transformInPlace(transform.kt:35) at org.jetbrains.kotlin.ir.declarations.IrFile.transformChildren(IrFile.kt:40) at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitPackageFragment(IrElementTransformerVoid.kt:41) at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitFile(IrElementTransformerVoid.kt:47) at org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext.visitFileNew(IrElementTransformerVoidWithContext.kt:122) at org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext.visitFile(IrElementTransformerVoidWithContext.kt:55) at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitFile(IrElementTransformerVoid.kt:48) at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitFile(IrElementTransformerVoid.kt:24) at org.jetbrains.kotlin.ir.declarations.IrFile.accept(IrFile.kt:30) at org.jetbrains.kotlin.ir.declarations.IrFile.transform(IrFile.kt:33) at org.jetbrains.kotlin.ir.declarations.IrFile.transform(IrFile.kt:21) at org.jetbrains.kotlin.ir.util.TransformKt.transformInPlace(transform.kt:35) at org.jetbrains.kotlin.ir.declarations.IrModuleFragment.transformChildren(IrModuleFragment.kt:51) at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitModuleFragment(IrElementTransformerVoid.kt:33) at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitModuleFragment(IrElementTransformerVoid.kt:38) at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitModuleFragment(IrElementTransformerVoid.kt:24) at org.jetbrains.kotlin.ir.declarations.IrModuleFragment.accept(IrModuleFragment.kt:41) at org.jetbrains.kotlin.ir.declarations.IrModuleFragment.transform(IrModuleFragment.kt:44) at io.sentry.compose.JetpackComposeTracingIrExtension.generate(JetpackComposeTracingIrExtension.kt:266) at org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory.convertToIr$lambda$1(JvmIrCodegenFactory.kt:186) at org.jetbrains.kotlin.psi2ir.Psi2IrTranslator.generateModuleFragment(Psi2IrTranslator.kt:104) at org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory.convertToIr(JvmIrCodegenFactory.kt:218) at org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory.convertToIr(JvmIrCodegenFactory.kt:55) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.convertToIr(KotlinToJVMBytecodeCompiler.kt:225) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:102) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli$default(KotlinToJVMBytecodeCompiler.kt:47) at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:167) at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:53) at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:101) at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:47) at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101) at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:485) at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:131) at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.doCompile(IncrementalCompilerRunner.kt:424) at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl(IncrementalCompilerRunner.kt:360) at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileNonIncrementally(IncrementalCompilerRunner.kt:242) at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:98) at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:625) at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:101) at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1746) at jdk.internal.reflect.GeneratedMethodAccessor167.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:360) at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200) at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197) at java.base/java.security.AccessController.doPrivileged(AccessController.java:712) at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196) at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:587) at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828) at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:705) at java.base/java.security.AccessController.doPrivileged(AccessController.java:399) at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) at java.base/java.lang.Thread.run(Thread.java:833)
The critial line would be
at io.sentry.compose.JetpackComposeTracingIrExtension$generate$transformer$1.visitFunctionNew(JetpackComposeTracingIrExtension.kt:149)
, in my opinion.
The situation might only arise in my project, if you guys cannot reproduce it, I'm happy to provide more information. Just tell me what you need.
I managed to get more out of the error dialog:
ASM Instrumentation process wasn't able to resolve some classes, this means that
the instrumented classes might contain corrupt stack frames. Make sure the
dependencies that contain these classes are on the runtime or the provided
classpath. Otherwise, the jvm might fail to load the corrupt classes at runtime
when running in a jvm environment like unit tests.
Classes that weren't resolved:
> io.sentry.instrumentation.file.SentryFileWriter
> androidx.compose.ui.semantics.SemanticsModifier
> androidx.navigation.NavDestination
> androidx.compose.animation.tooling.ComposeAnimatedProperty
> java9.util.concurrent.CompletionException
> io.netty.handler.proxy.Socks5ProxyHandler
> io.netty.handler.proxy.Socks4ProxyHandler
> io.netty.handler.proxy.HttpProxyHandler
This info might be related for you guys, and helpful.
hi @rolandsarosy-fizetesipont thanks for reporting! Could you share the versions of Kotlin and Compose that you're using?
Of course!
Jetpack Compose BOM and libraries: "2023.10.01"
Jetpack Compose Activity library: "1.8.0"
AndroidX Navigation - Compose: "2.7.4"
Kotlin version: "1.8.10"
I think that would be all, @romtsn
@rolandsarosy-fizetesipont I believe you'd need to bump Kotlin to 1.8.20
and then it should work. Could you try that?
I'll try it right away and get back to you within 25 minutes, thank you.
I can confirm that the build now properly compiles and we are getting automated composable tagging. Thank you for the quick assistance, @romtsn .
@rolandsarosy-fizetesipont just curious, where did you find out about the compiler plugin? Is it this docs page https://docs.sentry.io/platforms/android/enhance-errors/kotlin-compiler-plugin/? I'd like to update them to state the min supported kotlin version and wanna make sure I cover every possible place
@romtsn Yes, I found the docs page you linked, and installed given those instructions.
The way I stumbled upon that docs page was the following:
- I was integrating various parts of sentry (extended context, user logging support, Room support, Timber support, etc)
- I got to the Compose integration docs
- I was attempting to implement User Interactions
- I read the following under User Interactions / Usage:
If a @composable doesn't have a testTag modifier applied, both breadcrumbs and transactions won't be captured because they can't be uniquely identified. To automatically generate tags, refer to the docs about our Sentry Kotlin Compiler Plugin.
And lastly, I followed the link there, as frankly put, marking each and every composable myself in my entire codebase, sounded like hell on Earth. :')
Great, thanks for the detailed response, I will update the docs with the min Kotlin version requirement then!