'Source code does not match the bytecode'

2020-01-28 04:15发布

I have an app which I am compiling against API level 21: enter image description here

and then debug it on a real device with API level 23:

enter image description here

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. *enter image description here*

I am really confused. Can anyone explain why I am seeing this message and how I can fix it?

12条回答
Explosion°爆炸
2楼-- · 2020-01-28 04:36

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!

查看更多
来,给爷笑一个
3楼-- · 2020-01-28 04:36

I tried the solutions given here while working on an application that used Bluetooth Low Energy(BLE). I tried,

  1. Clean Build
  2. Disabled Instant Run
  3. 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.

查看更多
Lonely孤独者°
4楼-- · 2020-01-28 04:36

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.

by flagged I mean when you click on the left side where the line numbers are and it highlights the line. If that is not clear here are pictures.
go from: flagged line to: not flagged line

查看更多
做个烂人
5楼-- · 2020-01-28 04:39

My app is compiled on API LEVEL 29, but debugging on real device on API LEVEL 28.I got the warning source code does not match the bytecode in AndroidStudio.I fixed it thought these steps:

  1. Go to Preferences>Instant Run: uncheck the instant run

  2. Go to Build>Clean Build

  3. Re-RUN the app

Now, the debug runs normal.

查看更多
狗以群分
6楼-- · 2020-01-28 04:42

If you use Gradle, it is probably a problem with Gradle caches. (Reference). Alas, even if you run

gradle --refresh-dependencies

, 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.

查看更多
太酷不给撩
7楼-- · 2020-01-28 04:46

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.

查看更多
登录 后发表回答