Kotlin code stack trace shows Java line numbers
Asked Answered
N

2

10

I'm trying to debug a couple of crashes for my app in the Google Play Store, but the stack traces showing in the Play Store show Java filenames and line numbers instead of direct references to my Kotlin code. I viewed the Java code in Android Studio, but the line numbers do not match.

To view the Java code, I converted to byte code and then decompiled to Java. There's also a more direct option in Android Studio to 'Decompile Kotlin to Java', but this is disabled; my hope was that this would give me a better match against the stack traces.

How can I use the stack trace info I see in crash reports in the Play Store to identify the problems in my Kotlin source code?

Nervous answered 24/10, 2018 at 13:13 Comment(7)
Try 'Analyze stack trace', line numbers should become clickable.Emporium
@Emporium The stack trace is from a crash report on the Google Play StoreNervous
Yep, just copy it and paste into 'Analyze stack trace' in AS/IDEA.Emporium
Thank you! Could you make that an answer so I can accept it?Nervous
To decompile to Java see https://mcmap.net/q/50297/-how-to-convert-a-kotlin-source-file-to-a-java-source-file.Helvetic
It takes about an hour to decompile of 900 Kotlin lines. Creates a Java file of more than 200 Mb (shows only 2 Mb). Every Kotlin line is converted to several Java lines. Inner variables get names like "var10000" , methods and classes retain their names. You won't have right positions of stacktrace in created Java code.Helvetic
Is there any way to directly trace kotlin file with number?Acarpous
E
8

Copy your stack trace, open Android Studio or IntelliJ IDEA, click Analyze -> Analyze Stack Trace, paste it and click Ok. Class names with lines will become clickable and clicks should work correctly.

Emporium answered 24/10, 2018 at 14:45 Comment(8)
Please take a look on how questions should be asked on SO. You can't just ask the community to find articles, tutorials, or write the code for you. You must try to solve it yourself, and, when you struggle, ask a concrete question about a problem you facing.Emporium
I guess that comment you put here wasn't meant to show up here?Tyrelltyrian
Sorry, but lines become only clickable, nothing more. No references to original Kotlin code. For instance, SelectRaduisFragment.access$centerLocation(Unknown Source:97).Helvetic
Unknown Source means that LineNumberTable was obfuscated a bit. Try fixing stack trace either with retrace or by hand (e. g. by replacing Unknown Source with SelectRaduisFragment).Emporium
@Miha_x64, after an hour of decompiling to Java I got a huge Java-file. Crash log doesn't point neighter Kotlin, nor decompiled code. I suspect it points to Java lambdas. I don't know, how to retrace it.Helvetic
Decompiled Java lines won't ever point to Kotlin lines. Related: discuss.kotlinlang.org/t/…Emporium
@CoolMind, unfortunately, you're gonna need to repair file names by hand. SelectRaduisFragment.access$centerLocation is highly likely belong to the file that declares the outer class, typically SelectRaduisFragment.kt.Emporium
@Miha_x64, thanks for the answer. We closed and replaced that project, so I didn't solve the problem and haven't encountered it again.Helvetic
N
3

Answer update, in Android Studio 4.1, it looks like the menu option changed:

Analyze -> Stack Trace or Thread Dump...
Nervous answered 3/2, 2021 at 13:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.