Skip to content

Obfuscate an allowlist of libraries in Play builds - #2282

Draft
mpretty-cyro wants to merge 1 commit into
session-foundation:devfrom
mpretty-cyro:r8-obfuscation-allowlist
Draft

mpretty-cyro wants to merge 1 commit into
session-foundation:devfrom
mpretty-cyro:r8-obfuscation-allowlist

Conversation

@mpretty-cyro

@mpretty-cyro mpretty-cyro commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

Google Play requires app bundles to reach at least 25% in each of R8's obfuscation, optimisation and shrinking scores by February 2027. Play Console reports this app's obfuscation as 0%, because every build has had -dontobfuscate since #1889. This turns obfuscation on for Play builds, limited to libraries that are safe to rename.

What's renamed: AndroidX, Material, OkHttp/Okio and Glide. Everything else keeps its name, as before:

  • native code finds classes and members by name: libsession_util (including kotlin.Pair/kotlin.Triple), sqlcipher, conscrypt and WebRTC;
  • Kryo writes class names into persisted jobs, so a renamed class (Kotlin collections included) couldn't be read back by a later build;
  • protobuf, Jackson, kotlinx.serialization and Firebase reach code reflectively.

The renamed libraries' own consumer rules already keep their by-name entry points: XML-inflated views and CoordinatorLayout behaviours, WorkManager workers and input mergers, startup initializers and Glide's generated module. Coil stays out because it finds its decoders through ServiceLoader, so a renaming fault there would fail silently.

Which builds: the play flavour's release, releaseWithDebugMenu, qa and automaticQa are obfuscated. website, fdroid and huawei add proguard-dontobfuscate.pro and stay unobfuscated in every build type. debug isn't minified.

Scores: Play reads these from the r8.json that R8 writes into the bundle (BUNDLE-METADATA/com.android.tools/r8.json). Measured on playQa from the same commit:

obfuscation optimisation shrinking
dev 0.0% 84.8% 85.8%
this PR 49.6% 87.0% 87.9%

DEX is 0.6 MB larger (15.26 → 15.84 MB): R8 can't merge a class whose name is kept, so slightly fewer classes are merged than under -dontobfuscate. The universal APK grows 0.25%. R8 reports no warnings.

Crash reports: AGP already puts mapping.txt into the AAB (BUNDLE-METADATA/com.android.tools.build.obfuscation/proguard.map), so Play Console deobfuscates Play crashes. Session class and method names in traces and exported logs stay readable without the mapping. Line numbers already needed it (r8-map-id-<id>:N), and the id names the exact mapping file. Frames inside the renamed libraries need the mapping.

For traces from outside Play (exported logs, or play APKs installed from GitHub), the mapping is in the app-play-release.aab that the release script uploads to each GitHub release. It comes from the same R8 run as the play APKs:

gh release download <version> -R session-foundation/session-android -p app-play-release.aab
unzip -p app-play-release.aab BUNDLE-METADATA/com.android.tools.build.obfuscation/proguard.map > mapping.txt
$ANDROID_HOME/cmdline-tools/latest/bin/retrace mapping.txt trace.txt

The trace's r8-map-id-<id> should match the # pg_map_id: line at the top of mapping.txt.

Testing

  • testPlayDebugUnitTest: 461 tests pass.
  • Obfuscated playQa on two emulators, no app errors:
    • create and restore an account, link a device;
    • config sync and conversation settings;
    • 1:1, group and community messages;
    • images, voice messages, reactions with emoji search, quotes and disappearing messages;
    • a voice call;
    • FCM push;
    • Session Pro screens, Path and log export;
    • setting a profile picture.
  • Upgrade from a dev build while offline: an image upload and five send jobs persisted by the old build resumed in the new one, and sent once back online. Settings were kept.
  • Cold start is unchanged within emulator noise.

Play requires obfuscated DEX, and every build had obfuscation turned off. Play builds now
rename AndroidX, Material, OkHttp/Okio and Glide. Everything else keeps its name, since it is
reached by name from native code, Kryo-persisted jobs, reflection or ServiceLoader. The website,
F-Droid and Huawei builds keep -dontobfuscate.

R8's reported scores for playQa go from 0.0 / 84.8 / 85.8 to 49.6 / 87.0 / 87.9
(obfuscation / optimisation / shrinking). Crash traces from Play builds need the mapping file,
which the AAB carries for Play Console.
@mpretty-cyro
mpretty-cyro force-pushed the r8-obfuscation-allowlist branch from 543b4af to 9d8f565 Compare December 3, 2026 04:52

@mpretty-cyro mpretty-cyro left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant