I am debugging with Android Studio (A.S) 1.0.2 with compileSdkVersion 21 set up in build.gradle. When using an emulator with API 21 everything works fine. The problem occurs when debugging on a device having API 19. Each line in the call stack (tagged as 'Frames' in A.S) correctly shows the function name, source file and line number that matches API 19. However, when I click on one of the lines that corresponds with one of the framework sources (e.g. Activity.java), A.S incorrectly opens up and displays the API 21 version of the file rather than the API 19 version.
In my android sdk folder I have both ./sources/android-19 and ./sources/android-21
Any idea why A.S displays the wrong version of the file?
Things I tried (in order):
To summarize, when clicking on a line in the call stack A.S opens up the version of the file represented by compileSdkVersion and not the one used by the device/emulator during the debug session.
Even if the compileSdkVersion and targetSdkVersion have completely different meanings they are obviously not independent. targetSdkVersion cannot be higher than the compileSdkVersion simply because we cannot target things that we know nothing about during compilation.
Step 1: Open your project in Android mode then go to Gradle Scripts > build. gradle(Module: app) as shown in the following image. Step 2: Refer to the below image and here you have to change the minSdkVersion and targetSdkVersion as per the requirement.
Open the app on your phone. In the Devices view, expand the entry for your phone if it isn't already expanded, and look for your app's package name. Click on the package name, and in the top right of the Devices view you should see a green bug along with a number of other small buttons. Click the green bug.
Answered with working solution here:
https://stackoverflow.com/a/32236703/1267536
Full content:
I use appcompat support library quite a lot. Changing the compileSdkVersion only results in massive compile errors. If you are using appcompat-21, you must compile against api 21 or you will get compile errors.
This works fine if you are debugging against version 21. But when you are debugging on Jelly Bean (API 17), your debugger keeps dropping you to the API 21 source. Very annoying and hard to debug.
The solution I've ended up using is very hacky but works! Let's say you are trying to debug against API 17. Do the following:
Just don't forget to put all the directories back after you're done.
Here's an android studio bug report about this issue: https://code.google.com/p/android/issues/detail?id=183976
Open your project in Intellij Idea (Android Studio based on it) and choose File -> Project Structure...
. In project setting select "project SDK" to version which you need debug and select for all project modules "project SDK" as module SDK. After that you can attach debug connection to your device/emulator and see proper Android source.
You don't need to build project in Intellij Idea.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With