“源代码与字节码不匹配"华为系统文件 [英] "Source code does not match the bytecode" for system files on Huawei

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

问题描述

我们正在调试我们的一个应用程序的问题,该问题仅影响华为设备.为了调试它,我们购买了 P20 Lite ANE-LX1.我们在代码中放置了一些断点,并正在调查完整的堆栈跟踪.设备安装了 Android 8.0,我们在 Android Studio 中下载了相同的 SDK.

We are debugging an issue with one of our apps which affects only Huawei devices. To debug it, we purchased P20 Lite ANE-LX1. We've placed some breakpoints in our code and are investigating the full stack trace. The device has Android 8.0 installed, and we have the same SDK downloaded in our Android Studio.

当我们将设备连接到调试器并尝试调查堆栈跟踪时,我们在系统源文件中收到以下错误:

When we attach our device to a debugger and try to investigate the stack trace we get the following errors in system source files:

使用堆栈跟踪后,我们可以确认我们的源文件确实与设备上安装的文件不对应.有时,调试器指向调用 functionA 的行,在堆栈跟踪中,我们看到 functionB 被调用.我们可以确认受此问题影响的文件有:

After playing with the stack trace, we can confirm that indeed our source files do not correspond to what is installed on the device. Sometimes, the debugger points to a line where functionA is called, and in the stack trace, we see that functionB is called instead. The files which we could confirm are affected by this issue are:

  1. VideoView,
  2. MediaPlayer,
  3. ContentProvider.

我们已经尝试了我们能找到的所有可能的解决方案,包括清理项目、从 Android Studio 中删除任何额外的 SDK、修改项目设置 - 没有任何帮助来解决这个问题.

We've tried all the possible solutions which we could find, including cleaning the project, deleting any additional SDKs from Android Studio, modifying project settings - nothing helps to resolve this issue.

这让我们相信华为在他们的设备上安装了 Android 8.0 的修改版本,这就是为什么我们无法调试系统文件的堆栈跟踪.我们确实联系了华为,试图澄清这一点.

This leads us to believe that Huawei installs a modified version of Android 8.0 on their devices which is why we cannot debug the stack trace for the system files. We did contact Huawei to try and clarify this.

与此同时,如果您能向我们提出任何相关的想法,我们将不胜感激.也许您知道在哪里可以获取华为在其设备上安装的源文件?或者您可能知道如何以其他方式修复源代码和字节码之间的这种不匹配?

In the meantime, we'd appreciate if you could throw any relevant ideas at us. Maybe you know where to get the source files which Huawei installs on their devices? Or maybe you know how to fix this mismatch between source code and bytecode in some other way?

按照罗伯特的建议,我卸载了 Android 26 的源代码,并在我的华为上再次运行了该应用程序.一跳进VideoView文件,看到如下图:

Following the advice of Robert, I uninstalled the source codes for Android 26 and ran the app again on my Huawei. As soon as I jumped into the VideoView file, I saw the following picture:

我点击了下载"它开始下载源文件:

I clicked on "Download" and it started downloading the source files:

此后,我能够进入 VideoView 并且它似乎工作正常.然而,在这一行之后,很明显这些源文件也是错误的:

After this, I was able to step into VideoView and it seemed to work fine. However, after this line it became obvious that these source files are also wrong:

当我尝试进入 requestLayout 函数时,我得到了这个:

When I try to step into the requestLayout function I get this:

而且这显然是一个错误的结果.事实上,如果我点击跳到下一行"我再次看到源代码与字节码不匹配的消息.

And it is obviously a wrong result. In fact, if I click on "Step to the next line" I see the message about source code mismatch with the bytecode again.

推荐答案

显然华为分叉了 AOSP 并修改了它的源代码.这是许多制造商所做的,只要源通过兼容性测试套件就完全没问题.我自己在华为 P20 上看到了与他们自定义 ROM 的方法有关的加密视频播放问题.

Apparently Huawei forked AOSP and modified it's sources. This is what many manufacturers do and it's perfectly fine as long as source passes the Compatibility Test Suite. I myself saw encrypted video playback issues on Huawei P20 related to their approach to customizing the ROM.

但回到正题——您可以从/system/framework/arm/boot.oat 或 boot-framework.oat 或/system/framework/boot.vdex 获取在您的设备上运行的确切框架代码.我不知道这些文件的确切结构,但它因 Android 版本和制造商而异.一旦你通过 adb pull 获得这些文件(你肯定需要 root 来做这件事)你可以使用 dex2jar 或其他工具执行 oat->dex、dex->​​jar,你将获得源代码.传统上可以从/system/framework/framework.jar 获取框架代码,但是在引入 ART 之后,这些文件在系统映像上通常是空的,而是使用预编译的框架代码.

But getting back to the point - you can get the exact framework code running on your device from /system/framework/arm/boot.oat or boot-framework.oat or /system/framework/boot.vdex. I don't know exactly how these files are structured but it varies between Android versions and between manufacturers. Once you get these files by adb pull (You surely need root to do this) you can perform oat->dex, dex->jar using dex2jar or other tools and you'll get the source. Traditionally it was possible to get framework code from /system/framework/framework.jar but after ART was introduced these files are often empty on system images and precompiled framework code is used instead.

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

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