'Source code does not match the bytecode' when debugging on a device
and then debug it on a real device with API level 23:
The problem is when I try debugging through the Android OS's own classes, I get 'Source code does not match the bytecode'. Why is this happening? The test device the app is running on is API level 23, and the source file being debugged is level 23 as well.
I am really confused. Can anyone explain why I am seeing this message and how I can fix it?
There's an open issue for this in AOSP, where some users have given possible solutions: https://code.google.com/p/android/issues/detail?id=225199&sort=-id&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars
The potential solutions given there (as of the date of this post) are:
- Click Build->Clean
- Disable Instant Run, in Settings->Build, Execution, Deployment
here is my solution
if you got more than one version libraries, it may help.
- set a breakpoint on the lib source code
- let the code run to the breakpoint
you will got these tips
click the arrow icon
you will got this
double click to select the correct lib (normally the highest version of the lib is correct)
if have clicked the "disable" button by mistake, you can enable it in the debugger setting
if you do not have the tips in the step 3, maybe you can check whether you have checked the setting options.
You should use an Android emulator with the same api level as the compileSdkVersion. In your case you should use Android emulator with api level 21.
If you use Gradle, it is probably a problem with Gradle caches. (Reference). Alas, even if you run
, it is not refreshing really all dependencies. Some rubbish remains. (Reference).
So, the most sure (but drastic and long) variant is to clear all inside from the [user]/.gradle/caches. Or to find your problem project there and clear only its caches.
I tried the solutions given here while working on an application that used Bluetooth Low Energy(BLE). I tried,
- Clean Build
- Disabled Instant Run
- Invalidate Caches / Restart
all of these failed.
What I did was debug the points where I thought I was getting the warning, I still got the warning but the application was working fine. You can disregard the warning.
Go to Project Settings > Artifacts. Select the artifact which has the problem. There is an option "Include in project build". This needs to be checked(enabled). For older versions of IntelliJ this option is "Make on build".
Probably this error message can have more than one cause, my case was not like the one from the OP, in my case this was due to a 3rd party library that required additional libraries.
For example: you manually add X.jar to your LIB, but this X.jar requires Z.jar to work.
It took me sometime to figure out, the message was not helping at all. I had to debug the app until I reached the crashing class, and in that class make sure that all imports were satisfied.
(Particualry: I added MercadoLibre-0.3.4.jar, which required commons-httpclient.jar)
Hope this helps!
This can also happen in case you have enabled ProGuard. In buildTypes set minifyEnabled false, shrinkResources false, useProguard false
I tried all the solution given here and none of them worked for me. In version 2019.1.3 I just clean & rebuild artifact and it worked; first do Build -> Build Artifacts... -> <select your artifact> -> Clean then click Build or Rebuild from same place.
Android Studio takes source version equal to Target Version in your application. Compilation performed with source version equal to above mentioned Compile Version. So, take care that in your project Compile Version == Target Version (adjust module's build.gradle file).
I had the same issue and found a solution. If you have a line flagged in red, it will give you this error, but if you un-flag all of the lines it will work normally.