Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio debugger highlights the wrong lines

This is a problem with dx, which is the part of the build that turns your Java .class files into .dx files for packaging into Android. According to this:

https://code.google.com/p/android/issues/detail?id=34193

if a function has multiple return paths, dx merges the return instruction into a single return instruction, so during debugging, the debugger can't tell which line a return belongs to and things jump around. This corresponds to what I see when I try to reproduce your problem: each time through the loop it does the if (a == 3) check, jumps to the return 0 at the end, and then jumps back into the loop. You're seeing that last return 0 get merged with the return retval in the middle of the loop.

I doubt this will be fixed any time soon, so you may just have to learn to live with it. Sorry, I know it's kinda crazy.


Try Build -> Rebuild project and then Shift + F9. You have outdated code running on application.


Here's what worked for me, at least for stepping into Android SDK source code:

  1. Install the SDK Platform and Sources for Android SDK for exactly the API level of the version of Android you are running during development (use the Android version history page to find out which API level your device has).
  2. Compile your app for exactly that version. For example, in Android Studio, open your app's build.gradle file and set the value of compileSdkVersion accordingly.
  3. Debug your app. When you step into Android SDK source, you should see the correct line.
  4. (optional) Recompile with the latest SDK before deploying. In other words, change compileSdkVersion back.