Android proguard obfuscated code is causing NullPointerException when it really shouldn't be

此生再无相见时 提交于 2019-12-03 14:11:26

OK, I think I got to the root of the issue/confusion.

One of the things proguard does is in-line some methods. Because of this, the entire contents of my setupContinue() function at the bottom of my constructor was added directly into the contents of my constructor. So now I have a bunch more code to review, and I do see some more possibilities for NPEs. I'm pretty sure I'll get to the bottom of my issue.

I figured this out by taking the obfuscated.jar that proguard produces, and running it through a decompiler. Its an interesting exercise as you get get little more insight into the inner workings of proguard. I highly recommend it for people wanting to better understand the impacts that proguard has on their code.

Your best bet would be to use the mapping.txt file and the retrace tool to find the exact location of the error. From there it would be easier to understand if it's indeed Proguard or some other end-case you didn't think of.

To do this, you need to copy the stack trace from the developer's console to another file, let's assume it's called

c:\trace.txt

Now, in your project, you'll find a Proguard folder with 4 files. Let's assume your project is in

c:\project

What you'll need to do is run the retrace tool (using the batch file for easier use) located at (change to the location of your Android Sdk folder) :

c:\android-sdk-windows\tools\proguard\bin\retrace.bat

Go to that folder and run:

retrace c:\project\proguard\mapping.txt c:\trace.txt

From there on, it would be much easier to figure our the exact line of the exception and to probably find the error.

From my experience, the only things that could get messed up are third party libraries. Normal Android code, for all my projects, was never harmed from obfuscation.

Sorry I can't post comments yet (I'm new to SO).

This could be another problem I've encountered myself. On some phones there was a problem at some point with missing Android libraries like a JSon library.

I'd recommend you take a closer look at what phones that actually get the NPE - there might be some similarities.

In my case it was the HTC Desire Z, that was missing the JSon library and so the app force closed every time the JSon part was called. The problem was fixed by HTC later on with a hotfix to the Desire Z's rom.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!