Upgrade to Pro — share decks privately, control downloads, hide ads and more …

DX/Proguard and D8/R8

DX/Proguard and D8/R8

The secret behind our applications.

Developing an Android application is an art, you need creativity, dexterity and lots of coffee. At the moment of publishing an application we have to perform an action called obfuscation, which allows us to eliminate methods, classes and other variables that are not being used, which allow us to reduce the size of our application and place a level of security so that they can't access to our source code easily, in this talk we will see the difference between these two tools, DX/Proguard vs R8/D8 and the good practices that exist.

Gustavo Lizárraga

September 18, 2019
Tweet

More Decks by Gustavo Lizárraga

Other Decks in Programming

Transcript

  1. “Medical writing is a "highly trained and calculated attempt to

    confuse the reader." Dr. Michael Crichton
  2. Obfuscation The obfuscation of code consists in reordering or altering

    the instructions of a program so that, although it performs the same function, its understanding is more difficult.
  3. LEET SPEAK It’s a writing format composed with alphanumeric. 3

    5 7 0 3 5 3 1 H 4 ( | < m 3 3 7 ! n 6 4 N D r 0 1 D |-| 0 |_ 4 ( 0 |\/| 0 3 5 7 4 5
  4. GYARU-MOJI Obfuscated Japanese writing style, popular among young ladies, does

    not summarize on the contrary they lengthen the words. おはよう 才(よчoぅ "Buenos días"
  5. CHI LANGUAGE Language used mostly by “Paceñas” ladies. Chiho chila

    chico chimo chies chitas Chime chigus chita chie chisa chichi chica
  6. YES

  7. CPU In every device, there is a CPU, which is

    responsible for solving the processes of your application.
  8. JVM to the rescue It’s a native process virtual machine,

    that is, executable on a specific platform, capable of interpreting and executing instructions expressed in a special binary code (the Java bytecode), which is generated by the Java language compiler.
  9. Java Bytecode: All variables are stored in a stack Dex

    Bytecode: All variables are stored in registers
  10. The dex approach is much more efficient and requires less

    space than a regular Java bytecode.
  11. *.java / *.kt *.xml Images/Videos AndroidManifest.xml Android Asset Packaging Tool

    (AAPT) Java/Kotlin Compiler R.java Compiled resources *.class Dex Compiler *.dex App.apk App.aab APK/App Bundle Builder
  12. ART (Android Runtime) The main difference was that ART wasn’t

    running Interpreter/JIT on run time. It executed the precompiled code from an .oat binary instead resulting in much better and faster runtime. AOT (Ahead of Time).
  13. Install/Update Unpack .dex Run AOT Compiler .AOT binary Run App

    Load .AOT binary Enjoy App Runtime Install time
  14. AOT Binary Profiles Dex Files ART JIT Interpreter ART Cold

    code Hot code NO AOT Binary Using AOT Binary dex2aot
  15. Proguard ProGuard obfuscates our code by changing the name of

    the variables, methods and classes, making them occupy much less.
  16. D8 (Dope8) Is a command line tool that Android Studio

    and the Android Gradle Plugin use to compile your project's Java bytecode into DEX bytecode that runs on Android devices.
  17. Simple application DEX + Proguard D8 + Proguard Results Build

    time 41s 655ms 39s 343 ms -2s 312ms Size 5.5 MB 5.3 MB -218.7 kb
  18. R8 R8 obfuscates our code by changing the name of

    the variables, methods and classes, making them occupy much less into dex compilation.
  19. COMPARISON DEX + Proguard D8 + R8 Results Build time

    41s 655ms 28s 592 ms -13s 0732ms Size 5.5 MB 5.2 MB -348.6 kb Method count 39.339 38.217 -1.122