19

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:

enter image description here

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.

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.

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?

Update 1

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:

enter image description here

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

enter image description here

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:

enter image description here

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

enter image description here

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.

Community
  • 1
  • 1
Andriy Gordiychuk
  • 6,163
  • 1
  • 24
  • 59
  • 2
    So you are trying to step into a method of one of the mentioned classes? If yes the source code will never be the same because the Android SDK only contains the API (usually classes with all necessary methods but empty methods), not the source code. Therefore the line numbers do not match. If you want the source code you have to clone the AOSP project (requires several GB download ans storage). – Robert Aug 09 '18 at 18:19
  • 1
    @Robert thank you very much for your response. Could you please elaborate on it? The thing is, I do have sources for Oreo 8.0 installed. When I open VideoView or any other class, I see all of their functions together with their implementation. In fact, you can see it for yourself in the screenshot which I attached to my question. When I go to SDK Manager, select Oreo 8.0 and click on "Show package details" I see that Android SDK Platform 26 AND Sources for Android 26 are installed. Are you sure that these are not the correct sources? – Andriy Gordiychuk Aug 10 '18 at 16:51
  • 2
    No, this is just the initial release by Google. Just look at the revision column. There are 10 revisions for the API but only one for the source code. Furthermore this are the AOSP sources from Google, not the one used by Huawei. If you want code from your device extract the related odex files and decompile the code. Then you will something that matches. Or check the "Huawei Open Source Release Center" for P20 releases. Not sure what is included in their packages. – Robert Aug 10 '18 at 19:03
  • 1
    BTW: AndroidStudio has also limited decompiling abilities. Have you tried to delete the "Sources for Android 26" package and let Android Studio interpret the byte code? As the message "Source code does not match byte code" demonstrates the byte code has already been retrieved from the device by AndroidStudio, but it does not use it because of the existing sources. – Robert Aug 10 '18 at 19:07
  • 1
    @Robert I have updated my answer with illustration about what happens if I delete Android 26 source files. Unfortunately, it seems that this approach doesn't work either... – Andriy Gordiychuk Aug 11 '18 at 14:38
  • if there is any code mismatch, how about you try installing the app in another device and start debugging it. Your "Code Mismatch" has nothing to do with Huawei's device. It could have happened anywhere. If you don't have another Huawei device, and you really think it's a device specific issue, I would suggest you build an emulator. If none of that is possible, share an APK from your Huawei to another android device and start debugging it. Use `ShareIt` app to share apk file to another device. If the problem persists, you need to install a fresh app in Huawei device – Daksh Gargas Aug 11 '18 at 14:44
  • @Dennis thank you for your input. The reason why I am interested in debugging this exclusively on Huawei is that our app malfunctions exclusively on Huawei. More specifically, it doesn't play any videos which are either downloaded in a Zip file or are downloaded in an expansion file. The same app works on all emulators with the same Android version and on ALL other devices running the same Android version. By the way, all other apps we found which have videos in Zip files are also not able to play them on my Huawei. This leads us to believe that Huawei is shipping a buggy version of Android. – Andriy Gordiychuk Aug 11 '18 at 14:48
  • Yeah, that happens with most of the MI devices too, if you can, try sharing the APK file from your Huawei device to another device. Becuase, the current problem is that you are unable to debug your app. So we should focus on figuring out if our device has the same code as we expect it to. – Daksh Gargas Aug 11 '18 at 14:50
  • My "MI" I mean "Xiaomi" devices – Daksh Gargas Aug 11 '18 at 15:01
  • @Dennis we have already verified that our code is executed in the same way on all devices (and emulators). However, given the difference in the result on Huawei devices, it is obvious that on Huawei devices, calls to system libraries have a different logic. Until we understand what that logic is, we cannot find a solution to mitigate this behaviour. I am afraid that running APK on another device will achieve nothing as other devices have correct logic in their system classes. By the way, we haven't tested on Xiomi - maybe those devices are affected as well. – Andriy Gordiychuk Aug 11 '18 at 15:13
  • What is your compileSDKversion? Does it work if you don't debug, but just navigate the code? Does it work for any other devices? – Mike Aug 16 '18 at 14:52

2 Answers2

1

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.

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.

0

I believe I ran into a similar issue on my phone, but I am using a Google Pixel. I was initially concerned that the phone was compromised somehow. I think it is less likely an issue with Huawei and more likely an issue with Android Studio not keeping the source packages up to date. Your Component Installer screenshot shows Android Studio downloading revision 1 of the SDK Source - yet most SDKs are using a later revision.

I detailed the solution to my problem elsewhere on StackOverflow: Source code does not match the bytecode for Android's View.java

curious_george
  • 622
  • 2
  • 8
  • 19