Digging into D8 and R8
summary
D8 replaces DX and folds Java 8 desugaring into dexing so command-line experiments reproduce how lambdas become generated classes, and D8 emits different Dalvik opcodes based on minSdk (example: not vs xor optimization that saves an instruction but avoids buggy phones). R8 replaces ProGuard by running shrink/optimize during dexing and proves things like class staticization for Kotlin companion objects and nullability-driven elim, plus range propagation that can remove hundreds of AndroidX API-level branches. Build-plugin flags enable each; try on a real APK to see size and opcode changes.
AI-written summary · about
chapters (11)
- 0:00Introduction to D8 and R8
- 1:09Compilation pipeline overview
- 3:15D8 replaces DX with modern techniques
- 8:09Lambda transformations in D8
- 11:58D8’s bite code optimizations
- 16:35R8 integrates minification
- 18:23Cotlin companion object optimization
- 23:40Nullability and dead code elimination
- 28:59API level conditional code removal
- 36:27Using D8 and R8 in Gradle
- 40:23Conclusion and next steps
related talks
28mBest practices using compilers in Android Studio
41mShrink, Secure & Optimize Your App With R8
55mCompilers. Dalvik. ART. And everything in between
35mUnderstanding the Kotlin to Dalvik bytecode translation
36mPractical obfuscation guide
42mUnderstanding the Kotlin to Dalvik bytecode translation
27mFrom ProGuard to R8: Take Care of Your Bytecode
35mWhat's in the Android Toolbox?
