在使用旧 API 的设备上调试时,Android Studio 显示来自 compileSdkVersion API 的源 [英] Android studio shows sources from API of compileSdkVersion when debugging on device with older API

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

问题描述

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

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.

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

In my android sdk folder I have both ./sources/android-19 and ./sources/android-21

知道为什么 A.S 会显示错误版本的文件吗?

Any idea why A.S displays the wrong version of the file?

我尝试过的事情(按顺序):

Things I tried (in order):

  • 重置 Android Studio(通过删除 ~/.AndroidStudio*)
  • 将 Android Studio 更新到最新版本
  • 在带有 API 21 - A.S 的模拟器上运行会显示文件的正确版本 (21).
  • 将 compileSdkVersion 更改为 19 并在 API 19 设备上运行 - A.S 在调用堆栈中显示正确的行号,并在正确的行中打开文件的正确版本 (API 19).
  • 将 compileSdkVersion 更改为 19 并在 API 21 模拟器上运行 - AS 在调用堆栈中显示对应于 API 21 的行号(在我看来这是正确的行为),但是,当单击它时,AS 错误地打开更新文件的 API 19 版本,而不是 API 21 版本.

总而言之,当单击调用堆栈中的一行时,A.S 会打开由 compileSdkVersion 表示的文件版本,而不是设备/模拟器在调试会话期间使用的版本.

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:

https://stackoverflow.com/a/32236703/1267536

完整内容:

我经常使用 appcompat 支持库.更改 compileSdkVersion 只会导致大量编译错误.如果您使用的是 appcompat-21,则必须针对 api 21 进行编译,否则会出现编译错误.

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.

如果您正在针对版本 21 进行调试,这可以正常工作.但是,当您在 Jelly Bean (API 17) 上进行调试时,您的调试器会不断将您转到 API 21 源.非常烦人且难以调试.

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.

我最终使用的解决方案非常笨拙但有效!假设您正在尝试针对 API 17 进行调试.请执行以下操作:

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. 重新启动android studio,以便它选择正确的路径.
  4. 调试

完成后别忘了把所有目录放回去.

Just don't forget to put all the directories back after you're done.

这是关于此问题的 android studio 错误报告:https://code.google.com/p/android/issues/详细信息?id=183976

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 的源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆