Android studio shows sources from API of compileSdkVersion when debugging on device with older API

前端 未结 5 1441
慢半拍i
慢半拍i 2020-12-13 12:46

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

相关标签:
5条回答
  • 2020-12-13 13:21

    Change temporary the folder name of source files in the SDK. For example you compiled against API level 23 but the device you're testing and debugging is API level 15. Then first compile and run it in debug mode, set a breakpoint. After that switch the names :

    $SDK_HOME$/sources/android-23/ -> $SDK_HOME$/sources/android-23-temp/
    $SDK_HOME$/sources/android-15/ -> $SDK_HOME$/sources/android-23/
    

    And when this is done then it is a good time to hit your breakpoint.

    This solution is assuming that you've installed both API level sources from SDK manager.

    0 讨论(0)
  • 2020-12-13 13:23

    Link to issue that tracks this problem.

    Android Studio 2.2 fixes it, and will jump to sources of API level that corresponds to the device that you're actually running on (as long as you have those sources installed). It was announced here.

    0 讨论(0)
  • 2020-12-13 13:31

    Try debugging your app on a real device, compiling with the device's SDK level. The line numbers in the call stacks will probably be "out of sync" for classes provided by the device.

    Android Studio can't reliably provide the correct sources for your running device. Even if it would take into account the SDK version of the device you are debugging on, the device's firmware could (and propably will) still be compiled from different source files and just be compatible to the API.

    I think that's why Android Studio just shows the compile SDK versions of the classes provided by the target device. It just shows the compiler's reference implementation.

    0 讨论(0)
  • 2020-12-13 13:36

    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:

    1. mv $ANDROID_HOME/sources/android-21 $ANDROID_HOME/sources/android-21-orig
    2. cp $ANDROID_HOME/sources/android-17 $ANDROID_HOME/sources/android-21
    3. restart android studio so it will pick up the correct paths.
    4. Debug

    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

    0 讨论(0)
  • 2020-12-13 13:40

    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.

    0 讨论(0)
提交回复
热议问题