本文介绍了当在具有较旧API的设备上进行调试时,Android studio会显示来自compileSdkVersion的API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Android Studio(A.S)1.0.2进行调试,并在build.gradle中设置了compileSdkVersion 21。
当使用带有API 21的模拟器时,一切都正常。
在具有API 19的设备上调试时出现问题。
调用堆栈中的每一行(标记为AS中的Frames)正确显示与API 19匹配的函数名称,源文件和行号
但是,当我点击与其中一个框架源(例如Activity.java)相对应的行之一时,AS不正确地打开并显示文件的API 21版本,而不是API 19版本。



在我的Android sdk文件夹中,我有
./sources/android-19和./sources/android-21



任何想法为什么AS会显示错误的文件版本?



我尝试的顺序(顺序):




  • 重置Android Studio(删除〜/ .AndroidStudio *)

  • 将Android Studio更新为最新版本

  • 在具有API 21的模拟器上运行 - AS显示正确的文件版本(21)。

  • 将compileSdkVersion更改为19并在API 19设备上运行 - AS显示正确调用堆栈中的行号并打开正确的文件版本(API 19)。

  • 将compileSdkVersion更改为19并在API 21模拟器上运行 - AS显示,在调用堆栈,对应于API 21(在我看来是正确的行为)的行号,然而,当点击它时,AS错误地打开了API 19版本的文件,而不是API 21版本。
  • $总而言之,当在调用堆栈中单击一行时,AS会打开由compileSdkVersion表示的文件的版本,而不是设备使用的文件版本/

    解决方案

    在这里回答工作解决方案:





    全部内容:



    我使用appcompat支持库很多。更改compileSdkVersion只会导致大量的编译错误。如果你正在使用appcompat-21,你必须编译api 21,否则你会收到编译错误。



    在Jelly Bean(API 17)上进行调试,您的调试器不断将您放在API 21源代码中。非常烦人,难以调试。



    我最终使用的解决方案非常简单,但可以工作!假设您尝试针对API 17进行调试。请执行以下操作:


    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. 将拿起正确的路径。

    4. 调试

    只要不要忘记将所有目录放回你完成。



    这是一个关于这个问题的android studio bug报告:


    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):

    • Resetting Android Studio (by removing ~/.AndroidStudio*)
    • Update Android Studio to latest version
    • Running on emulator with API 21 - A.S shows the correct version (21) of the files.
    • Changing compileSdkVersion to 19 and running on API 19 device - A.S shows the correct line numbers in call stack and opens the correct version (API 19) of the files in the correct line.
    • Changing compileSdkVersion to 19 and running on API 21 emulator - A.S shows, in the call stack, the line numbers corresponding to API 21 (which seems to me as the correct behavior), however, when clicking on it, A.S mistakenly opens up the API 19 version of the file rather than the API 21 version.

    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.

    解决方案

    Answered with working solution here:

    http://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

    这篇关于当在具有较旧API的设备上进行调试时,Android studio会显示来自compileSdkVersion的API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 05:30