leakcanary icon indicating copy to clipboard operation
leakcanary copied to clipboard

Deobfuscation plugin doesn't work with app bundles

Open mzgreen opened this issue 5 years ago • 1 comments

Leak Canary deobfuscation plugin doesn't work with app bundles. The mapping file is not being copied into the final .aab file. It sometimes works but most of the time it doesn't.

It can be reproduced by adding deobfuscation plugin to Leak Canary sample app and running ./gradlew leakcanary-android-sample:bundleDebug -Pminify

then after opening generated .aab file, there is no leakCanaryObfuscationMapping.txt file in the assets directory.

mzgreen avatar Sep 16 '20 04:09 mzgreen

This seems to be still broken in 2.9.1, but it's fairly easy to work around. Sharing this simple script in case its useful for anyone:

#!/bin/bash
set -eo pipefail

# To make sense of Leak traces in minified build, we need to include the generated mapping file in the bundle.
# Ideally, this should have been taken care of by LeakCanary's deobfuscation plugin, but
# it has known issues with AAB format: https://github.com/square/leakcanary/issues/1925

cd app/build/outputs/bundle/debug/
cp app-debug.aab app-debug.zip
mkdir modified
unzip app-debug.zip -d modified/
cp ../../../../build/outputs/mapping/debug/mapping.txt modified/base/assets/
mv modified/base/assets/mapping.txt modified/base/assets/leakCanaryObfuscationMapping.txt
cd modified/; zip -D -r ../modified.aab * -x '**/.DS_Store'; cd ..
rm app-debug.aab app-debug.zip
rm -rf modified/
mv modified.aab app-debug.aab # Replace original AAB!

vibin avatar Sep 13 '22 19:09 vibin