How to tell if Proguard has done its job
Asked Answered
R

2

25

I downloaded proguard encapsulated in a zip file and unpacked it onto my hard disk. I did not install it in any way (because I didn't know how). I then added proguard.config=proguard.cfg to my project.properties file. I then did an "export android application" fully expecting eclipse to complain that it didn't know where my proguard installation was, but there was no complaint. Indeed a new apk file appeared in my keystore, and a set of files (dump.txt etc) appeared in my app's proguard subdirectory. The mapping.txt looks like a nice list of mappings from my long variable names to one and two letter variables. This should all be strong evidence that proguard has somehow worked - my only concern is that the apk is scarcely any smaller than it was before. Is there any way to check that the apk includes proguard's obfuscations?

Ribwort answered 17/4, 2012 at 12:6 Comment(0)
G
46

Normally the size will indicate whether ProGuard has worked but you can :-

  1. Use Dex2Jar to convert the apk to a jar file
  2. Open the resulting Jar file with Jd-Gui to view the code it contains
Guenna answered 17/4, 2012 at 12:33 Comment(1)
For mac osx, brew install dex2jar, then /usr/local/Cellar/dex2jar/2.0/bin/d2j-dex2jar to run it on your classes.dex file. Rename your apk file to a .zip extension, then unzip and cd into folder, there should be a classes.dex file there you can run dex2jar on.Devious
C
1

An alternative to @Kuffs method would be to compare your new APK with an old one. Open them both up (with 7zip or your preferred tool) and compare the size of the classes.dex files in each of them.

A few straightforward reasons you might not be seeing much of a size saving:

  • The unobfuscated classes.dex was able to be compressed much more than the obfuscated one. This is always true to some extent.
  • You didn't do a release build. Proguard only gets run on release builds since debugging obfuscated code is a nightmare.
  • The Proguard settings you're using aren't doing much good (at least in terms of code size) for your project. I've actually seen proguard's code inlining settings increase the size of jar files before!
Cheney answered 17/4, 2012 at 12:46 Comment(2)
The unobfuscated classes.dex was able to be compressed much more than the obfuscated one -> does this mean unobfuscated classes.dex has less size than obfuscated one?Kammerer
@Kammerer I would always expect the size of the obfuscated .dex to be smaller than the unobfuscated one. However, I would also expect that the size difference after compression would be much smaller than the size difference before compression. This is because obfuscation does some of the same work that compression does - i.e. replacing long strings (class/method/field names) with much shorter ones.Cheney

© 2022 - 2024 — McMap. All rights reserved.