31

In the case, if I will

  • build a project
  • clean up all binaries
  • build it again (no source/resources and etc has changed).

Does Proguard guarantee to provide the same mapping.txt file?

Victor Ronin
  • 22,758
  • 18
  • 92
  • 184
  • I imagine it would generate the same output (and hence use the same mapping) - unless there is a RNG at play ;-) Given no change in inputs (including any RNGs) then the output should be identical .. consider an md5sum to give a quick "nod or shake" of such an assertion. However, since source often changes this really isn't the most useful question. –  Nov 28 '12 at 21:12

3 Answers3

45

ProGuard is deterministic: for the same input, it will generate the same output.

There is one subtlety though: if the operating system lists input files in a directory (notably class files that are not inside an archive) in a different order, then they may be processed in a different order, and the output can be different.

Eric Lafortune
  • 45,150
  • 8
  • 114
  • 106
  • Where's written in the ProGuard manual that it is deterministic? I can't find any reference in regard. – Stack Diego Feb 24 '14 at 11:15
  • 25
    @Diego I am the developer of ProGuard; you'll have to believe me on this one, or you can look at the source code. – Eric Lafortune Feb 27 '14 at 10:37
  • Thanks, @Eric, I forgot to version mapping.txt and was wondering about this, too. – arne.jans Jul 02 '15 at 14:35
  • 3
    @EricLafortune could this be fixed so that ProGuard would be completely deterministic across all operating systems? – Nicholas Mar 21 '16 at 13:10
  • @EricLafortune does this also hold true for the code-removal part of Proguard? Does this also hold true if the "file order" is influenced by the addition of file that will NOT be proguarded in the first place? – tir38 Nov 28 '17 at 18:59
7

It might actually happen, but i don't think proguard guarantees that.

I found this in the Proguard documentation that will allow you to reuse your mapping.txt to avoid changes on the mappings

-applymapping filename

Specifies to reuse the given name mapping that was printed out in a previous obfuscation run of ProGuard. Classes and class members that are listed in the mapping file receive the names specified along with them. Classes and class members that are not mentioned receive new names. The mapping may refer to input classes as well as library classes. This option can be useful for incremental obfuscation, i.e. processing add-ons or small patches to an existing piece of code. If the structure of the code changes fundamentally, ProGuard may print out warnings that applying a mapping is causing conflicts. You may be able to reduce this risk by specifying the option -useuniqueclassmembernames in both obfuscation runs. Only a single mapping file is allowed. Only applicable when obfuscating.

Community
  • 1
  • 1
Robert Estivill
  • 12,369
  • 8
  • 43
  • 64
0

If you want a guarantee then you have to use the mappings file as input to the obfuscation process. But then you carefully have to check all warnings about conflicts relating to that mapping file. If you ignore that, you may get subtle errors, when working with reflection.

AlexWien
  • 28,470
  • 6
  • 53
  • 83