Android Studio步入错误的sdk源代码

时间:2021-09-21 20:43:32

I've got the following build.gradle settings.

我有以下build.gradle设置。

compileSdkVersion 21
buildToolsVersion '21.1.1'

defaultConfig {
    minSdkVersion 18
    targetSdkVersion 21
}

The problem is that when I step into Android SDK source on an KitKat device (19 on Genymotion or Device), it still insists on stepping into Android-21 source instead of 19.

问题是,当我在KitKat设备(Genymotion或Device上的19)上进入Android SDK源时,它仍然坚持步入Android-21源而不是19。

Changing any of the above settings simply breaks the compilation of my app since I have v21 code. All 19 calls are protected properly and the code works on 19, just the source code linkup is incorrect.

更改上述任何设置只会破坏我的应用程序的编译,因为我有v21代码。所有19个调用都受到正确保护,代码工作在19,只是源代码链接不正确。

Cheers in advance Stack Overflow brothers and sisters!

提前干杯Stack Overflow兄弟姐妹们!

3 个解决方案

#1


10  

Edit (7/1/2016):
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.

编辑(2016年7月1日):Android Studio 2.2修复它,并将跳转到与您实际运行的设备相对应的API级别的源(只要您安装了这些源)。它在这里宣布。


The following workaround worked for me:

以下解决方法对我有用:

  1. Compile the application without any changes.
  2. 编译应用程序而不做任何更改。

  3. Launch the application in Debug mode (and optionally break on breakpoint).
  4. 在调试模式下启动应用程序(并可选择在断点处中断)。

  5. Go to File > Project Structure, find your app module (or/and optionally, any other modules) and change the Compile Sdk Version to one that matches the device you're debugging on (i.e. 19).
  6. 转到文件>项目结构,找到您的应用程序模块(或/和/或可选的任何其他模块),并将Compile Sdk Version更改为与您正在调试的设备匹配的版本(即19)。

  7. Step into the framework code - it should step into SDK 19 sources.
  8. 进入框架代码 - 它应该进入SDK 19源代码。

#2


5  

As was mentioned in another answer, it was fixed in Android Studio 2.2 (bug report).

正如在另一个答案中提到的,它已在Android Studio 2.2中修复(错误报告)。

However, it still wasn't working for me even in Android Studio 3.0 It started working only after I checked "Show alternative source switcher" in Settings.

但是,即使在Android Studio 3.0中它仍然无法正常工作。只有在我在“设置”中选中“显示替代源切换器”后才开始工作。

screenshot

#3


1  

What happens if you try to debug into the source on an emulator that is running an android 5.0.x Lollipop image? Does it highlight the correct source? I have been struggling with this as well, and I reached the conclusion that the problem is due to customizations to the android source by the hardware vendor.

如果您尝试在运行Android 5.0.x Lollipop映像的模拟器上调试源代码会发生什么?它是否突出了正确的来源?我一直在努力解决这个问题,我得出的结论是问题是由于硬件供应商对android源的定制。

I have been trying to step through the android source code on a samsung device running 4.4.2 KitKat. Some files line up well, some are off by a few lines, and the rest are way out of whack. Instrumentation.java is one that I routinely find myself in. It is off by 5 lines or so.

我一直试图在运行4.4.2 KitKat的三星设备上逐步浏览android源代码。有些文件排成一行,有些文件排除了几行,其余文件都没有出现问题。 Instrumentation.java是我经常发现自己的东西。它大约5行左右。

So why do I think the vendor customized the android source? I stepped through application startup in ActivityThread.java and Instrumentation.java. The debugger will still step correctly even though the source doesn't line up. I cross referenced the routine I was in with android source code on grepcode.com. Eventually I see the debugger step into a function call that is not present in any version of the java file posted on grepcode.

那么为什么我认为供应商定制了android源码呢?我在ActivityThread.java和Instrumentation.java中完成了应用程序启动。即使源不排队,调试器仍将正确步进。我在grepcode.com上交叉引用了我在android程序源代码中的例程。最后,我看到调试器步骤进入函数调用,该函数调用在grepcode上发布的任何java文件版本中都不存在。

Here is a specific example: ActivityThread.HandleLaunchActivity. I witnessed the debugger making these calls

这是一个具体的例子:ActivityThread.HandleLaunchActivity。我亲眼目睹了调试人员进行这些调用

unscheduleGcIdler          : present in android source
intent.getWindowStyle      : not present. Samsung customization?
handleConfigurationChanged : present

If I am right, then the debugger should step through an emulated image correctly, since it won't contain vendor customized code.

如果我是对的,那么调试器应该正确地逐步调试模拟图像,因为它不包含供应商定制的代码。

#1


10  

Edit (7/1/2016):
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.

编辑(2016年7月1日):Android Studio 2.2修复它,并将跳转到与您实际运行的设备相对应的API级别的源(只要您安装了这些源)。它在这里宣布。


The following workaround worked for me:

以下解决方法对我有用:

  1. Compile the application without any changes.
  2. 编译应用程序而不做任何更改。

  3. Launch the application in Debug mode (and optionally break on breakpoint).
  4. 在调试模式下启动应用程序(并可选择在断点处中断)。

  5. Go to File > Project Structure, find your app module (or/and optionally, any other modules) and change the Compile Sdk Version to one that matches the device you're debugging on (i.e. 19).
  6. 转到文件>项目结构,找到您的应用程序模块(或/和/或可选的任何其他模块),并将Compile Sdk Version更改为与您正在调试的设备匹配的版本(即19)。

  7. Step into the framework code - it should step into SDK 19 sources.
  8. 进入框架代码 - 它应该进入SDK 19源代码。

#2


5  

As was mentioned in another answer, it was fixed in Android Studio 2.2 (bug report).

正如在另一个答案中提到的,它已在Android Studio 2.2中修复(错误报告)。

However, it still wasn't working for me even in Android Studio 3.0 It started working only after I checked "Show alternative source switcher" in Settings.

但是,即使在Android Studio 3.0中它仍然无法正常工作。只有在我在“设置”中选中“显示替代源切换器”后才开始工作。

screenshot

#3


1  

What happens if you try to debug into the source on an emulator that is running an android 5.0.x Lollipop image? Does it highlight the correct source? I have been struggling with this as well, and I reached the conclusion that the problem is due to customizations to the android source by the hardware vendor.

如果您尝试在运行Android 5.0.x Lollipop映像的模拟器上调试源代码会发生什么?它是否突出了正确的来源?我一直在努力解决这个问题,我得出的结论是问题是由于硬件供应商对android源的定制。

I have been trying to step through the android source code on a samsung device running 4.4.2 KitKat. Some files line up well, some are off by a few lines, and the rest are way out of whack. Instrumentation.java is one that I routinely find myself in. It is off by 5 lines or so.

我一直试图在运行4.4.2 KitKat的三星设备上逐步浏览android源代码。有些文件排成一行,有些文件排除了几行,其余文件都没有出现问题。 Instrumentation.java是我经常发现自己的东西。它大约5行左右。

So why do I think the vendor customized the android source? I stepped through application startup in ActivityThread.java and Instrumentation.java. The debugger will still step correctly even though the source doesn't line up. I cross referenced the routine I was in with android source code on grepcode.com. Eventually I see the debugger step into a function call that is not present in any version of the java file posted on grepcode.

那么为什么我认为供应商定制了android源码呢?我在ActivityThread.java和Instrumentation.java中完成了应用程序启动。即使源不排队,调试器仍将正确步进。我在grepcode.com上交叉引用了我在android程序源代码中的例程。最后,我看到调试器步骤进入函数调用,该函数调用在grepcode上发布的任何java文件版本中都不存在。

Here is a specific example: ActivityThread.HandleLaunchActivity. I witnessed the debugger making these calls

这是一个具体的例子:ActivityThread.HandleLaunchActivity。我亲眼目睹了调试人员进行这些调用

unscheduleGcIdler          : present in android source
intent.getWindowStyle      : not present. Samsung customization?
handleConfigurationChanged : present

If I am right, then the debugger should step through an emulated image correctly, since it won't contain vendor customized code.

如果我是对的,那么调试器应该正确地逐步调试模拟图像,因为它不包含供应商定制的代码。