desugar_globals output is not reproducible (zip entry order varies)

Open
#610 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 6 days

@TrapsterDK is already working on this.

Since Nov 28, 2026.

  • #611 by @TrapsterDK — open
  • #614 by @paladine — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
30/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
android, java, shell

Research direction

Start with the //tools/android:desugar_globals and desugar_globals_classes genrules in tools/android/BUILD, then run the issue’s GlobalSyntheticsGenerator reproduction command. The work is done when both genrules enable deterministic mode and repeated runs produce identical .globals output that can be remote-cached. Note that linked PR #611 already proposes this change.

Written by the indexing model from the issue text.

Description

//tools/android:desugar_globals is not reproducible. The genrule runs R8's GlobalSyntheticsGenerator and the entry order of the .globals zip it writes changes from run to run. The zip is the input of desugar_globals_dex_archive, so the same source tree gives different outputs and misses the remote cache.

Reproduce with the R8 version rules_android pins (com.android.tools:r8:9.3.16), without Bazel. The command line is the one in tools/android/BUILD:

curl -sSLO https://maven.google.com/com/android/tools/r8/9.3.16/r8-9.3.16.jar
for i in 1 2 3 4 5 6 7 8; do
  java -Dcom.android.tools.r8.disableLambdaMethodAnnotations \
    -cp r8-9.3.16.jar com.android.tools.r8.GlobalSyntheticsGenerator \
    --min-api 23 --output run$i.globals
done
sha256sum run*.globals | cut -d' ' -f1 | sort | uniq -c

Actual: 8 runs gave 4 different hashes (3/3/1/1). unzip -Z1 shows the same six entries in different orders, for example RecordTag.global first in one run and DesugarVarHandle$0.global first in another.

Expected: the same bytes on every run.

Adding -Dcom.android.tools.r8.deterministicdebugging=1 to the command makes all 8 runs identical (one hash, 8/8).

The --classfile variant used by desugar_globals_classes produced identical output in 12 runs here, but it runs the same generator.

Environment: Linux x86_64, OpenJDK 25, rules_android main (5a9ce60), same behavior expected for 0.8.1.

I will send a PR that sets the flag on both genrules.

Assisted by Claude.

Dominant language
Java
Stars
205
Forks
113
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bazelbuild/rules_android

All issues in bazelbuild/rules_android

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.