源代码与Android的View.java的字节码不匹配 [英] Source code does not match the bytecode for Android's View.java

查看:141
本文介绍了源代码与Android的View.java的字节码不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试调试我的Android应用.当调试器到达View.java文件时,我收到消息源代码与字节码不匹配".我可以看到调试器位于文件的错误部分.有人知道如何解决这个问题吗?

I am attempting to debug my Android app. When the debugger gets to the View.java file, I receive the message, "Source code does not match the bytecode". I can see that the debugger is in the wrong part of the file. Does anyone know how to fix this?

我正在Android 10(API 29)设备上进行调试.在Android Studio偏好设置中->外观行为->系统设置->Android SDK,我确保所有内容都是最新的.我还多次清理和重建,删除缓存,重新启动Android Studio和设备,卸载/重新安装,将Android Studio更新到4.0.1.在模块设置"中,编译SDK版本"是29,目标SDK版本和Min SDK版本为29.没有任何帮助或影响.在类似的帖子中建议了其中许多步骤.

I am debugging on an Android 10 (API 29) device. In the Android Studio Preferences -> Appearance & Behavior -> System Settings -> Android SDK, I've made sure everything is up to date. I've also cleaned and rebuilt multiple times, removed caches, restarted Android Studio and the device, uninstalled/re-installed, updated Android Studio to 4.0.1. In the Module Settings, the "Compile Sdk Version" is 29, and the Target SDK Version and Min SDK Version to 29. Nothing helps or has any effect. Many of these steps were suggested in similar posts.

它尝试打开的View.java文件位于:〜/Library/Android/sdk/sources/android-29/android/view/View.java.这应该是正确的文件,但是当我收到错误消息时,调试器位于文件的错误部分.

The View.java file it tries to open is at: ~/Library/Android/sdk/sources/android-29/android/view/View.java. This should be the correct file, yet the debugger is in the wrong part of the file while I get the error message.

戴上黑帽,让我们假设笔记本电脑的View.java在该API级别上是正确的:我的手机可以运行非标准代码吗,有什么方法可以检测出该错误或将其排除?

Putting on my black hat, let's assume that my laptop's View.java is correct for that API level: could my phone be running non-standard code, and is there any way to detect that or rule it out?

推荐答案

我想我知道发生了什么,当Android SDK文件发生此问题时,我有解决方案.令人恐惧的是,Android SDK平台已更新至修订版5,但未更新源软件包.它仍在修订版1中!为什么发生这种情况,我无法解释:一个有理智的人会期望两者保持同步.此屏幕快照显示了源代码与Android Studio下载的二进制文件不匹配:

I think I figured out what was happening and I have a solution for this problem when it happens with Android SDK files. Frighteningly, the Android SDK Platform gets updated to Revision 5, but the source package is not updated. It is still on Revision 1! Why this happened, I cannot explain: a reasonable person would expect both to be in sync. This screenshot shows the source code does not match the binary that Android Studio downloaded:

唯一的解决方法是手动下载所需文件,然后在SDK源目录中手动对其进行修补.这很丑陋,没有必要,但是如果您真的想逐步浏览特定的SDK文件,则必须这样做.

The only way around this is to manually download the files you need and patch them manually in your SDK source directory. It's ugly, it's unnecessary, but if you really want to step through a specific SDK file you have to do it.

  1. 找出您拥有的Android版本.在您的设备上,转到设置"->关于电话"->"Android版本",并记下您的内部版本号"价值.我的是QQ3A.200805.001.

  1. Find out what Android build you have. On your device, go to "Settings" -> "About phone" -> "Android version", and note down your "Build number" value. Mine is QQ3A.200805.001.

使用此页面找到与您的内部版本号相对应的标记: https://source.android.com/setup/start/build-numbers#source-code-tags-and-builds .对于我的内部版本号,标记为:android-10.0.0_r41

Find out the Tag corresponding to your Build number using this page: https://source.android.com/setup/start/build-numbers#source-code-tags-and-builds. For my build number, the tag is: android-10.0.0_r41

为此标签下载AOSP源.如果您是第一次这样做,这将花费很长时间.有关如何执行此操作的示例,请参见 https://stackoverflow.com/a/14353644/259718 .

Download the AOSP source for this tag. This takes a long time if you are doing this for the first time. See https://stackoverflow.com/a/14353644/259718 for an example on how to do that.

复制文件以覆盖某些源目录:cp -pr〜/android_src/frameworks/base/core/java/android/*〜/Library/Android/sdk/sources/android-29/android/(使用适合您环境的正确位置,此处我使用android-29进行编译)

Copy the files to overwrite some of the source directories: cp -pr ~/android_src/frameworks/base/core/java/android/* ~/Library/Android/sdk/sources/android-29/android/ (use the correct location for your environment, here I am compiling with android-29)

虽然不是android源文件夹中的所有目录都被覆盖,但核心android文件却被覆盖.这些构成了源材料的大部分.如果您需要其他目录(例如"filterpacks"),则必须在其他AOSP目录中找到该目录(例如"filterpacks"的frameworks/base/media).

While not all of the directories in the android sources folder are overwritten, the core android files are overwritten. These comprise the majority of the source material. If you need other directories (e.g. "filterpacks"), you'll have to find that in the other AOSP directories (e.g. frameworks/base/media for "filterpacks").

以下是我仅获取一个文件的步骤:

Here are the steps I followed to get just one individual file:

  1. https://android.googlesource.com 上找到所需的文件.使用google.com,我在以下位置找到了它:
  1. Find the file you need on https://android.googlesource.com. Using google.com, I found it at: https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/view/View.java
  2. Determine the Android repo your file lives in. Looking at the previous URL, I can deduce it's at: https://android.googlesource.com/platform/frameworks/base/
  3. Grab that repo using your tag. Or grab that tag's most recent revision of that individual file on-line, e.g.: https://android.googlesource.com/platform/frameworks/base/+log/refs/tags/android-10.0.0_r41/core/java/android/view/View.java, revision 18c0fbf.
    • To download the individual file, add "?format=text" to the URL to get the base64 encoded version. Then decode it: cat file | base64 --decode.

我希望这会在将来对其他人有所帮助.我花了很多时间来解决这个问题,我衷心希望其他人不必浪费时间.Google需要使源软件包与发行软件包保持一致.查看所有过去的SDK版本,似乎没有任何源软件包与最新版本同步.调试SDK文件的另一种丑陋方式是使用与版本1原始程序包匹配的版本1 SDK发行版.

I hope this helps someone else in the future. I spent a lot of time figuring this out and I sincerely hope someone else won't have to waste that time. Google needs to keep the source packages consistent with the release packages. Looking at all the past SDK releases, none of the source packages appear to be in sync with the latest release version. Maybe another ugly way to debug SDK files is to use a Revision #1 SDK release version that matches the Revision #1 source package.

这篇关于源代码与Android的View.java的字节码不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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