I have an app which I am compiling against API level 21:
and then debug it on a real device with API level 23:
The problem is when I try debugging
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 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.
You can created AVD, select API Level equal your tagetApi andr compileApi, it works for me.
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.
Here is my solution:
If you got more than one library version, this may help.
click the arrow icon
you will get this
double click to select the correct lib (normally the highest version of the lib is correct)
I 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
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:
Go to Preferences>Instant Run: uncheck the instant run
Go to Build>Clean Build
Re-RUN the app
Now, the debug runs normal.