r/reactnative • • 1d ago

Why is dex code optimization at 0% in android

/r/expo/comments/1y3loza/why_is_dex_code_optimization_at_0_in_android/
2 Upvotes

9 comments sorted by

2

u/Western_Cap_6934 1d ago

A possible cause is -dontoptimize in the generated release R8 configuration. It disables code optimization while shrinking and obfuscation can still run.

1

u/Miserable-Pause7650 1d ago

I checked that already and I dont think I have it in the generated prebuild. Will check again when I get home thanks!

2

u/Western_Cap_6934 1d ago

Prebuild files are only part of the picture. R8 can merge rules from other sources. Adding -printconfiguration build/outputs/logs/configuration.txt to the rules file used by the release build writes the final merged rules, so you can check what R8 actually received.

1

u/Miserable-Pause7650 20h ago

2

u/Western_Cap_6934 20h ago

That would explain why prebuild looked clean: the Amazon module can bring the flag in through consumer rules, even for non-Amazon apps.

1

u/atta542 1d ago

if it's a prebuild/bare project check android/app/build.gradle. the RN template uses getDefaultProguardFile("proguard-android.txt") and that default file has -dontoptimize in it, so R8 shrinks and obfuscates but skips optimization, which would line up with what you're seeing. switching it to proguard-android-optimize.txt is usually what turns it on, and the -printconfiguration tip above will confirm it either way. just test the release build properly after, optimization can break stuff that relies on reflection

1

u/Miserable-Pause7650 1d ago

Thanks I will do it later :)