5

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?

Crag
  • 1,241
  • 9
  • 27
  • Try 'Analyze stack trace', line numbers should become clickable. – Miha_x64 Oct 24 '18 at 13:28
  • @Miha_x64 The stack trace is from a crash report on the Google Play Store – Crag Oct 24 '18 at 13:36
  • Yep, just copy it and paste into 'Analyze stack trace' in AS/IDEA. – Miha_x64 Oct 24 '18 at 14:05
  • Thank you! Could you make that an answer so I can accept it? – Crag Oct 24 '18 at 14:36
  • To decompile to Java see https://stackoverflow.com/a/54116131/2914140. – CoolMind Jun 27 '19 at 09:40
  • 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. – CoolMind Jun 27 '19 at 12:26
  • Is there any way to directly trace kotlin file with number? – Nidhi Desai Jul 10 '20 at 06:51

2 Answers2

6

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.

Miha_x64
  • 4,532
  • 1
  • 35
  • 56
  • 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. – Miha_x64 Nov 05 '18 at 12:15
  • I guess that comment you put here wasn't meant to show up *here*? – GhostCat Nov 05 '18 at 12:54
  • 5
    Sorry, but lines become only clickable, nothing more. No references to original Kotlin code. For instance, `SelectRaduisFragment.access$centerLocation(Unknown Source:97)`. – CoolMind Jun 27 '19 at 09:27
  • `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`). – Miha_x64 Jun 27 '19 at 10:05
  • @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. – CoolMind Jun 27 '19 at 12:10
  • Decompiled Java lines won't ever point to Kotlin lines. Related: https://discuss.kotlinlang.org/t/stacktrace-points-to-line-after-end-of-file/4129 – Miha_x64 Jun 27 '19 at 12:58
2

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

Analyze -> Stack Trace or Thread Dump...
Crag
  • 1,241
  • 9
  • 27